Skip to content

Add layer names #4066

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
TylerGrantSmith opened this issue Jun 16, 2020 · 2 comments · Fixed by #5967
Closed

Add layer names #4066

TylerGrantSmith opened this issue Jun 16, 2020 · 2 comments · Fixed by #5967
Labels
feature a feature request or enhancement layers 📈

Comments

@TylerGrantSmith
Copy link

I don't know if there is much demand for such a feature, but I often find myself wanting to modify ggplot objects after they are constructed (zapping a layer, for example), but in order to do so, I need to know the index of the layer to modify.

Could there be a name parameter for layers?

df <-
  tibble(x = runif(1000, 0, 1)) %>% 
  mutate(y = x + runif(1000, x, 1)) 

g <-
  df %>% 
  ggplot() +
  geom_point(aes(x = x, y = y), alpha = 0.2) +
  geom_smooth(aes(x = x, y = y))

g$layers[[1]] <- NULL  

# would rather do something like 
# ... +
# geom_point(aes(x = x, y = y), alpha = 0.2, name = "scatter") +
# ...
# 
# g$layers[["scatter"]] <- NULL
@smouksassi
Copy link

while not answering your request you might want to look at gginnards:
https://cran.r-project.org/web/packages/gginnards/vignettes/user-guide-2.html
it will let you manipulate layers not just remove them e.g. you want to put points on top of the lines or vice versa etc.

@thomasp85
Copy link
Member

I think there are many future scenarios where named layers would be beneficial so we should definetly look into that. I've also wanted it for gganimate and ggforce to better target effects on specific layers

@thomasp85 thomasp85 added feature a feature request or enhancement layers 📈 labels Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement layers 📈
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants