Question: I'm trying to create a map of U.S. states/counties with the sf package and geom_sf()
from ggplot2, but I can't get the size
argument for polygon border line width in geom_sf()
to properly create thin lines when size < 1
(e.g. ggplot(sf_obj) %>% geom_sf(size = 0.5)
.
Specifically, the border lines of a state/county appear to have the same width from the arbitrarily small (e.g. size = 0.05
) all the way up to size = 0.702
. Then there seems to be a strange cutoff at size = 0.702
, above which the border lines abruptly appear wider. Then from size = 0.703
up to size = 1
the border lines appear to have the same width. For size
> 1, the border lines appear gradually wider, as expected.
Research: It does appear that geom_sf()
supports gradual changes in size
< 1, as shown in the code for maps by Bob Rudis here and Matt Strimas-Mackey here. It seems like my issue may be the same one referenced here on ggplot2's Github page titled "geom_sf rounds small sizes up to 1", but the issue was closed and I'm not sure if/how I can implement the fix on my machine. There's another similar-looking issue filed here (and here), but Hadley suggested that the problem in this case may be the graphics device/viewer. I replicated my issue (and the two Github issues linked above) in RStudio and RGUI, but I'm not sure how else to test/change my graphics device/viewer.
Version info: I'm using ggplot2_3.0.0, sf_0.6.3, R version 3.5.1, RStudio version 1.1.456, and Windows 10 version 1803; the issue was also replicated using RGUI.
Code: Below is a reprex using the North Carolina map from the geom_sf()
docs. Any help would be appreciated. Thanks!
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(reprex))
suppressPackageStartupMessages(library(sf))
#################################################
# plot north carolina map
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc) + geom_sf(size = 0.05)
nc %>% ggplot() + geom_sf(size = 0.702)
nc %>% ggplot() + geom_sf(size = 0.703)
# get version info
packageVersion("ggplot2")
#> [1] '3.0.0'
packageVersion("sf")
#> [1] '0.6.3'
version
#> _
#> platform x86_64-w64-mingw32
#> arch x86_64
#> os mingw32
#> system x86_64, mingw32
#> status
#> major 3
#> minor 5.1
#> year 2018
#> month 07
#> day 02
#> svn rev 74947
#> language R
#> version.string R version 3.5.1 (2018-07-02)
#> nickname Feather Spray
UPDATE: As Chris and Ibusett pointed out, the border lines have the expected width after using ggsave
. Thanks!