Skip to content
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

Feature request: default plot argument for layer_*() functions #5166

Closed
teunbrand opened this issue Jan 29, 2023 · 3 comments · Fixed by #5187
Closed

Feature request: default plot argument for layer_*() functions #5166

teunbrand opened this issue Jan 29, 2023 · 3 comments · Fixed by #5187
Labels
feature a feature request or enhancement

Comments

@teunbrand
Copy link
Collaborator

I'm estimating that about 4 out of 5 times that layer_data(), layer_grob() or layer_scales() is used, my intention is to get that information from the plot currently on display.

I think it is a good default to have plot = last_plot() be the default value for these functions, for the following reasons:

  • The current default, i.e. no value, is useless in 5 out of 5 times.
  • I can think of no alternative default value that might be useful.
  • It may save folks 11 keystrokes.
  • For people that don't know about last_plot(), as I did for a long time, using last_plot() is more convenient than using
p <- ggplot(...) + ...
layer_data(p)
@teunbrand teunbrand added the feature a feature request or enhancement label Jan 29, 2023
@thomasp85
Copy link
Member

I've never really used these functions outside of unit tests and I do consider them semi-private...

but, I see no harm in introducing a default

@teunbrand
Copy link
Collaborator Author

I use it mostly to debug the data when a plot doesn't turn out as I'd expected, so often I'd need the current plot for that. For this use-case, having the last plot as a default is convenient.

There are a few (less legitimate?) use cases outside debugging as well, when you'd like to compute something on whatever a stat has computed. An example of this is: you draw a density plot, and use the density layer's data to identify the group-wise mode to plot a line at that point as an annotation.

@yutannihilation
Copy link
Member

I too use them for debugging purposes, so I think I will also find this useful. Anyway, as it seems we all agree adding this feature should make no harm, I'm going to approve #5187.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants