Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change alpha in geom_sf?

Tags:

r

ggplot2

sf

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)
like image 860
Dambo Avatar asked Feb 18 '19 05:02

Dambo


People also ask

What does Alpha do in Geom_point?

Alpha refers to the opacity of a geom. Values of alpha range from 0 to 1, with lower values corresponding to more transparent colors.

How do you make a transparent Geom point?

Another technique is to make the points transparent (e.g. geom_point(alpha = 0.05) ) or very small (e.g. geom_point(shape = ".") ).

What is geom_ sf()?

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.


1 Answers

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))

enter image description here

like image 82
Nakx Avatar answered Oct 19 '22 10:10

Nakx