Skip to content

Feature Request: Syntactic sugar for theme #5301

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

Closed
teunbrand opened this issue May 9, 2023 · 0 comments · Fixed by #5430
Closed

Feature Request: Syntactic sugar for theme #5301

teunbrand opened this issue May 9, 2023 · 0 comments · Fixed by #5430

Comments

@teunbrand
Copy link
Collaborator

teunbrand commented May 9, 2023

I have two ideas for making themes slightly easier to use.

Element shortcuts

Often, you simply want to switch a theme element on or off.
For example if you want to put axis lines on and legend titles off, you can use:

ggplot(mpg, aes(displ, hwy, colour = drv)) +
  geom_point() +
  theme(
    legend.title = element_blank(),
    axis.line    = element_line()
  )

It would be neat if we could write:

ggplot(mpg, aes(displ, hwy, colour = drv)) +
  geom_point() +
  theme(
    legend.title = "blank",
    axis.line    = "line"
  )

Subtheme

Another idea for theme specification, is that we could have subtheme functions. So instead of writing this:

ggplot(mpg, aes(displ, hwy, colour = drv)) +
  geom_point() +
  theme(
    axis.line.x.bottom  = element_line(colour = "red"),
    axis.ticks.x.bottom = element_line(colour = "red"),
    axis.text.x.bottom  = element_text(colour = "red")
  )

We could write this:

ggplot(mpg, aes(displ, hwy, colour = drv)) +
  geom_point() +
  theme_axis_bottom(
    line  = element_line(colour = "red"),
    ticks = element_line(colour = "red"),
    text  = element_text(colour = "red")
  )

Which would then simply feed forward those arguments as the axis.{part}.x.bottom arguments to the theme(). One could have similar subthemes for the legend, the panel etc. It might also encourage a more ordered approach of theme specification, instead of the wild west that is currently theme declarations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant