This requires the libraries sf and ggplot2 in R. I have a sf object with 4 linestrings. 3 of these are identical and one is extended:
a <- st_linestring(rbind(c(2,2), c(3,3), c(3,2)))
b <- st_linestring(rbind(c(2,2), c(3,3)))
c <- st_linestring(rbind(c(2,2), c(3,3)))
d <- st_linestring(rbind(c(2,2), c(3,3)))
testsf <- st_sf(object = c(1, 2, 3, 4), geometry = st_sfc(a, b, c, d), crs = 4326)`
If I plot this in ggplot2 with alpha = 0.1, I would expect that the diagonal line is darker than the vertical line as it occurs more often. This is normal (non-sf) behaviour in ggplot2.
ggplot(data = testsf) + geom_sf(data = testsf, alpha = 0.1, lwd = 2, color = "black")
However, all lines appear to be equal alpha. Why is this occurring?
Update: If i try
testsf %<>% dplyr::mutate(geochar = as.character(geometry)) %>% dplyr::group_by(geochar) %>% dplyr::tally() %>% sf::st_cast()
ggplot(data = testsf) + geom_sf(data = testsf, aes(alpha = n), lwd = 2, color = "black")
the legend shows alpha changing as if it is a polygon...perhaps geom_sf is not properly handling alpha for lines (note, above code requires dplyr and magrittr packages)
I filed an issue at github.com/edzer/sf.
https://github.com/edzer/sfr/issues/311#issuecomment-296752334
This is not yet supported in geom_sf. Hopefully in the near future...
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