-
-
Notifications
You must be signed in to change notification settings - Fork 20
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: easy functions should work on more specific theme elements #75
Comments
This might actually be an issue with the implemented theme or library(ggplot2)
library(ggeasy)
p <- ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
hrbrthemes::theme_ipsum()
p # these doesn't remove axes
p + ggeasy::easy_remove_axes() p + theme(axis.text = element_blank()) # but these do
p + ggeasy::easy_remove_x_axis() p + ggeasy::easy_remove_y_axis() I think this also has to do with re-defining theme elements. If I manually change a specific theme element, I need to be specific when removing it library(ggplot2)
p2 <- ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme_classic()
# if a theme element is set manually, the inheritance doesn't work
p2 + theme(axis.line.x = element_line(color = "red")) # the red x-axis remains, even though "everything" is removed
p2 + theme(axis.line.x = element_line(color = "red")) + ggeasy::easy_remove_axes() # you need to specifically reset that element
p2 + theme(axis.line.x = element_line(color = "red")) + ggeasy::easy_remove_x_axis() In terms of the inheritance working properly, it seems the "right" way is that new theme elements should be registered and their place in the element tree defined. See: https://ggplot2.tidyverse.org/reference/register_theme_elements.html But I can't find a single package that does it properly. {ggside} was the closest I could find https://github.com/jtlandis/ggside/blob/main/R/zzz.R -- it does do the registering, but it doesn't define any elements that inherit from a default one. I might reach out to the community to better understand why setting e.g. |
"the most specific theme element wins" appears to be expected behaviour, now that I see this video https://resources.rstudio.com/resources/rstudioglobal-2021/always-look-on-the-bright-side-of-plots/ (around 18:10 mark). I might have to play around with detecting already set elements and inheritances. It would be nice if |
I think almost no-one understands this. That quoted expression is a nice way to describe it. It affects most of your functions. I reckon a If you default to |
Part of the problem would be figuring out which more specific elements have been set by the theme, in order to remove those. That gets even trickier if packages define their own with the registration mechanism. We could just loop through all the ones we know about and explicitly remove those, but my heuristic for "is this too complicated for ggeasy" is usually how bad does the It's still true that being specific in the |
I think you just define at the lowest level, and then you over-rule everything So
And
The teach statements in specific = TRUE would be bad, but that would still teach users about all the downstream layers required to make sure something definitely happens |
I reckon it would make ggeasy even more useful, if you could be confident that each easy function would just work regardless of the underlying theme (which often people are unaware what's in it anyway - as someone else made it) |
@teunbrand has an implementation of the recursive application in tidyverse/ggplot2#5694 so I'll add that to {ggeasy}. I will see how well it can be used throughout. |
Awesome function! I'd vote for making the functions default to recursive, so that they always "just work". This is what the user most wants when they add a ggeasy function |
Lots of theme elements might have more specific theme elements specified than that which the ggeasy function affects.
In these cases, the ggeasy function does not work - and users will often be confused.
Ideally it would just work regardless of the theme elements already specified - as the user just wants to remove them all.
An idea is to have an argument within these easy functions to be as specific as possible.
I'm thinking a
specific = TRUE
argument - or abroad = FALSE
argument.Not sure whether it would default to being specific or not. That would depend if your priority was teaching users, or just doing what the user wants to do. I'd vote for just working being the priority. I know how ggplot2 theme statements work, but I prefer to just use ggeasy.
For example, with
easy_remove_y_axis(what = "text", specific = TRUE)
or equivalent argument, it would add:theme(axis.text.x.bottom = element_blank(), axis.text.x.top = element_blank())
Created on 2024-02-15 with reprex v2.1.0
The text was updated successfully, but these errors were encountered: