简体   繁体   中英

How to specify shape for color legend?

I am plotting spatial point data ( sf ) with ggplot2 . Color is mapped to an associated value. The legend for color is unexpectedly using a polygon shape as it would for a two-dimensional geom that might have separate color and fill attributes. Is there a way to specify that the shape for the color legend so that I can make it a filled circle?

library(sf)
library(ggplot2)

set.seed(2)
df <- data.frame(x = runif(10, min = 0, max = 10),
                 y = runif(10, min = 0, max = 10),
                 value = sample(c(FALSE, TRUE), 10, replace = TRUE))
sf <- st_as_sf(df, coords = c("x", "y"))

ggplot(sf, aes(color=value)) +
  geom_sf()

在此处输入图像描述

The proper way to do this is as below:

ggplot() +
  geom_sf(data = sf, aes(color=value), show.legend = "point") 
# you can also choose "line" for instance

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM