Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size legend of sf object won't show correct symbols

Does anyone know why the legend of the size aestatic BIR74 won't show the dot sizes but rectangles? If the answer is yes, how can I fix this?

Reproducable example:

library(sf)
# devtools::install_github("tidyverse/ggplot2")
library(ggplot2)

nc <- st_read(system.file("shape/nc.shp", package="sf"))

nc_centers <- st_centroid(nc)

nc_centers %>%
  ggplot() +
  geom_sf(aes(color = SID79, size = BIR74)) +
  coord_sf(datum = NA) +
  theme_minimal()

enter image description here

like image 438
Tdebeus Avatar asked Mar 29 '18 12:03

Tdebeus


1 Answers

you need to add the show.legend argument to geom_sf, i.e.

nc_centers %>%
  ggplot() +
  geom_sf(aes(color = SID79, size = BIR74), show.legend = 'point') +
  coord_sf(datum = NA) +
  theme_minimal()

enter image description here

like image 90
sebdalgarno Avatar answered Sep 21 '22 10:09

sebdalgarno