Is there a way to change alpha
with geom_sf
? This example is from the examples in ?geom_sf
. I tried adding alpha=.2
but it seems to ignore that aesthetic, although alpha
is an accepted aesthetic for geom_line
. It does not ignore alpha for the fill
- which in this example is NA
though.
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3
library(ggplot2)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
nc_3857 <- sf::st_transform(nc, "+init=epsg:3857")
ggplot() + geom_sf(data = nc) +
geom_sf(data = nc_3857, colour = "red", fill = NA, alpha = 0.2)
Alpha refers to the opacity of a geom. Values of alpha range from 0 to 1, with lower values corresponding to more transparent colors.
Another technique is to make the points transparent (e.g. geom_point(alpha = 0.05) ) or very small (e.g. geom_point(shape = ".") ).
geom_sf() uses a unique aesthetic: geometry , giving an column of class sfc containing simple features data. There are three ways to supply the geometry aesthetic: Do nothing: by default geom_sf() assumes it is stored in the geometry column. Explicitly pass an sf object to the data argument.
It's called an outline. I never worked with maps and the result is not quite pretty but I hope this is still helpful and this could help you more: ggplot2: different alpha values for border and filling of geom_point
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3
library(ggplot2)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
nc_3857 <- sf::st_transform(nc, "+init=epsg:3857")
ggplot() + geom_sf(data = nc) +
geom_sf(data = nc_3857, color=alpha("red",0.2))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With