Skip to content

geom_sf alpha not working for linestring  #311

@sebdalgarno

Description

@sebdalgarno

I expected alpha to work for linestring sf object as in geom_line. Here is a simple example:

library(ggplot2)
library(sf)

l <- st_linestring(rbind(c(2,2), c(3,3), c(3,2)))
lsf <- st_sf(geometry = st_sfc(l, crs = 4326))

ggplot(data = lsf) + geom_sf(data = lsf, lwd = 2)
ggplot(data = lsf) + geom_sf(data = lsf, alpha = 0.5, lwd = 2)

both plots above are identical.

If I try with polygon, fill transparency changes but outline remains the same.
p <- st_polygon(list(rbind(c(2,2), c(3,3), c(3,2), c(2,2))))
psf <- st_sf(geometry = st_sfc(p, crs = 4326))

ggplot(data = psf) + geom_sf(data = psf)
ggplot(data = psf) + geom_sf(data = psf, alpha = 0.5)

Using geom_line, it works:
lpt <- st_coordinates(lsf) %>% tbl_df()
ggplot() + geom_line(data = lpt, aes(x = X, y = Y), alpha = 0.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions