Skip to content

Point symbols do not appear in the legend [geom_sf] #3572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kadyb opened this issue Oct 16, 2019 · 3 comments · Fixed by #3646
Closed

Point symbols do not appear in the legend [geom_sf] #3572

kadyb opened this issue Oct 16, 2019 · 3 comments · Fixed by #3646

Comments

@kadyb
Copy link

kadyb commented Oct 16, 2019

I chose point symbols, they appeared on the map, but didn't appear in the legend.

library("sf")
library("ggplot2")
df = data.frame(x = 1:2, y = 1:2, val = 3:4, shape = factor(1:2))
df = st_as_sf(df, coords = c("x", "y"), crs = 27700)

ggplot(df) +
   geom_sf(aes(color = val, shape = shape))

Imgur

@clauswilke
Copy link
Member

Apparently the legend type is hardcoded and is not auto-detected:

legend = if (is.character(show.legend)) show.legend else "polygon",

Manually setting it to "point" works, but if we could add auto-detection that would be great.

library("sf")
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library("ggplot2")
df = data.frame(x = 1:2, y = 1:2, val = 3:4, shape = factor(1:2))
df = st_as_sf(df, coords = c("x", "y"), crs = 27700)

ggplot(df) +
  geom_sf(aes(color = val, shape = shape), show.legend = "point")

Created on 2019-10-16 by the reprex package (v0.3.0)

@clauswilke
Copy link
Member

With current ggplot2 master:

library("sf")
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library("ggplot2")
df = data.frame(x = 1:2, y = 1:2, val = 3:4, shape = factor(1:2))
df = st_as_sf(df, coords = c("x", "y"), crs = 27700)

ggplot(df) +
  geom_sf(aes(color = val, shape = shape))

Created on 2019-12-06 by the reprex package (v0.3.0)

@lock
Copy link

lock bot commented Jun 24, 2020

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants