Skip to content

Add layer names #4066

Closed
Closed

Description

@TylerGrantSmith

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

Activity

  1. smouksassi commented on Jun 17, 2020

    @smouksassi

    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.

  2. thomasp85 commented on Aug 31, 2020

    @thomasp85
    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

  3. added
    feature
    on Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurelayers 📈

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions