Skip to content

Feature Request: Syntactic sugar for theme #5301

Closed

Description

@teunbrand

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions