I hope this is not a silly and already answered question but I couldn't find any solution until now. When plotting a polygon using ggplot2 I can easily define the properties (e.g. colour, size) of the border via geom_polygon(colour = "red", size = 2). But when I set the size values to have very thin borders (let's say 10^-2 or smaller), there is no effective change in the border size and from what I tested so far it is not a matter of the resolution. Is there any explanation for that?
Example code:
usa <- map_data("usa")
ggplot() + geom_polygon(data = usa, aes(x=long, y = lat, group = group), colour = "red", size = 0.5)
ggplot() + geom_polygon(data = usa, aes(x=long, y = lat, group = group), colour = "red", size = 0.005)
ggplot() + geom_polygon(data = usa, aes(x=long, y = lat, group = group), colour = "red", size = 0.00005)
Maybe I misunderstand the question, but aren't tiny changes in size indistinguishable with standard, granular screen resolutions?
Here's a discussion on size in ggplot "ggplot2 Quick Reference: size". It mentions that size is in absolute terms. A size of 0.00005 is probably indistinguishable from zero on your computer screen.
Hi EconomiCurtis, thanks for your feedback! I was also thinking about a resolution issue but I cannot even see a difference going from 0.05 to 0.005 to 0.0005 (pages 2 to 5 here: https://document.li/6j6m; unfortunately, I cannot upload attachments). Isn't there any way to have tiny borders for? If I wrap them to a facet, the maps are 95% white and 5% filling (despite saving the map in very high resolution).
I think 0.05 to 0.005 to 0.0005 are too small to see any change.
If that ggplot2 Quick Reference: size link above is approximately correct, "A size of 1 corresponds to approximately 0.75 mm".
And so size = 0.05 is 0.0375mm.
On an iPhone or retina mac, a pixel is 0.09652mm. So your line thickness is less than half a retina pixel.
As with so many things in life, I think you're just going to want to play with it until you get 'er looking right.
Here's a few options I messed with:
#setup
library(maps);library(dplyr);library(ggplot2)
usa <- map_data("usa")
#too small
usa %>% ggplot() +
geom_polygon(
aes(x=long, y = lat, group = group), colour = "red",
size = 0.001)
#too big
usa %>% ggplot() + geom_polygon(
aes(x=long, y = lat, group = group), colour = "red",
size = 1)
#nice looking...?
usa %>% ggplot() + geom_polygon(
aes(x=long, y = lat, group = group), colour = "red",
size = 0.15)
You got to check out reprex
If you make a plot, it'll automatically upload your plot to imgur and save a community-post-friendly code snippet to your clipboard, linking to imgur, ready to paste into community (or SO or github)!
Use devtools::install_github("tidyverse/reprex") for now, but the nice version of reprex is coming to CRAN very soon.
Thanks again for your effort and tips! Regarding my border size issue, the only option seems to increase resolution (as you also nicely explained). I thought I might miss something...
And I will definitely check out that reprex package, looks awesome