-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
geom_sf() now seems unable to plot filled polygons without any gap or border between them. Now it always adds a thin border (sometimes one pixel wide) between them.
What I expected, and what geom_sf() has done in the past (unfortunately I don't know the version), was to plot adjacent filled polygons without any space between them. This was possible, and it's helpful for plotting choropleths with many small regions. With borders between every region, it's very visually distracting.
I've looked through the docs, blogs, stackoverflow, etc., and the received wisdom is that setting colour=NA removes borders. And I guess it does, but previously the fill would go right out to the edge and now it does not.
Here is the code to reproduce the bug:
# overbuilt function to make a unit square
st_square <- function(x, y) {
sf::st_polygon(
x = list(
matrix(
data = c(x, y, x, y + 1, x + 1, y + 1, x + 1, y, x, y),
ncol = 2,
byrow = TRUE
)
)
)
}
# create a set of 100x100 unit squares
many_squares <- purrr::map(1:100, \(x) {
purrr::map(1:100, \(y) {
st_square(x, y)
})
}) |>
unlist(recursive = FALSE) |>
sf::st_sfc(crs = 32189)
# plot the squares filled with black and no colour. There should be lines between all of them
many_squares |>
ggplot2::ggplot() +
ggplot2::geom_sf(fill = "black", colour = NA)Image output:
Session info:
> sessionInfo()
R version 4.5.0 (2025-04-11)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.5 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0 LAPACK version 3.10.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: Etc/UTC
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_4.0.1
loaded via a namespace (and not attached):
[1] gtable_0.3.6 dplyr_1.1.4 compiler_4.5.0 maps_3.4.3 reprex_2.1.1 tidyselect_1.2.1 Rcpp_1.1.0
[8] clipr_0.8.0 unigd_0.1.2 systemfonts_1.1.0 scales_1.4.0 textshaping_0.4.0 R6_2.6.1 labeling_0.4.3
[15] generics_0.1.3 classInt_0.4-11 sf_1.0-16 tibble_3.2.1 units_0.8-1 DBI_1.2.3 pillar_1.9.0
[22] RColorBrewer_1.1-3 rlang_1.1.6 utf8_1.2.3 fs_1.6.6 S7_0.2.1 viridisLite_0.4.2 cli_3.6.5
[29] withr_3.0.2 magrittr_2.0.4 class_7.3-23 grid_4.5.0 rstudioapi_0.14 lifecycle_1.0.4 vctrs_0.6.5
[36] KernSmooth_2.23-26 proxy_0.4-27 glue_1.8.0 farver_2.1.2 ragg_1.3.3 httpgd_2.0.2 fansi_1.0.4
[43] e1071_1.7-13 purrr_1.0.1 tools_4.5.0 pkgconfig_2.0.3