Skip to content

Don't modify legend key settings in geom_sf() during plot build. #3942

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

Merged
merged 2 commits into from
Apr 16, 2020

Conversation

clauswilke
Copy link
Member

Fixes #3941.

library(ggplot2)

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
p <- ggplot(nc[1:3, ]) +
  geom_sf(aes(color = NAME), show.legend = "point")
p

p

Created on 2020-04-11 by the reprex package (v0.3.0)

@yutannihilation
Copy link
Member

Looks good, but as I don't quite remember the discussion on #3646, l need some more time to see the context...

@yutannihilation
Copy link
Member

After reading the comments around #3646 (comment), I remembered I once proposed a similar approach, but it uses param$legend directly. Here's a version for this PR:

yutannihilation@2b6317d

Do you think we need to introduce a new parameter on LayerSf rather than recycling legend (or some other parameters in geom_params)?

@clauswilke
Copy link
Member Author

I think writing to params$legend directly can create a warning of an unknown parameter if you're using the layer with a geom that doesn't have a legend parameter.

@yutannihilation
Copy link
Member

I see. So, can we do this in geom_sf()?

@yutannihilation
Copy link
Member

I mean, if this is specific to geoms that have a legend parameter, it makes sense to do it in geom_sf(). If this is more general one, this should be done in layer_sf(). (And I'm getting to feel the latter is right...)

Copy link
Member

@yutannihilation yutannihilation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some thinking, I'm sure this is the best fix at the moment.

@clauswilke clauswilke merged commit a637fbf into tidyverse:master Apr 16, 2020
@clauswilke clauswilke deleted the issue-3941-sf-legend branch April 16, 2020 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Legend keys from geom_sf() change upon repeat printing of the same plot
2 participants