You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
Activity
smouksassi commentedon Jun 17, 2020
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 commentedon Aug 31, 2020
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