Skip to content

Add layer names #4066

Closed
Closed
@TylerGrantSmith

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions