Skip to content

Setting theme() after using a complete theme (like theme_minimal()) no longer worksΒ #6591

@thomasjwood

Description

@thomasjwood

It used to be the behavior of ggplot that you could use a default theme (like theme_minimal()) and then specify a further change with a subsequent use of theme(). That no longer seems to be the case.

library(tidyverse)
library(ggtext)

ggplot(
  economics, aes(date, unemploy)
  ) + 
  geom_line() +
  scale_x_date(
    breaks = seq.Date(
      "1970-01-01" %>% as.Date,
      "2012-01-01" %>% as.Date, 
      length.out = 5
      ),
    labels = str_c(
      "**",
      seq(1970, 2010, by  = 10),
      "**"
      )
  ) +
  theme(
    axis.text.x =  element_markdown()
  ) 

returns:
Image

Now, imagine if I wanted to keep the markdown for the x axis labels, but use theme_minimal() otherwise. You formerly could use

ggplot(
  economics, aes(date, unemploy)
  ) + 
  geom_line() +
  scale_x_date(
    breaks = seq.Date(
      "1970-01-01" %>% as.Date,
      "2012-01-01" %>% as.Date, 
      length.out = 5
      ),
    labels = str_c(
      "**",
      seq(1970, 2010, by  = 10),
      "**"
      )
  ) +
  theme_minimal() +
  theme(
    axis.text.x =  element_markdown()
  ) 

but now it returns (ie the theme(axis.text.x = ....) is ignored.)

Image

How can one set a theme() element after using a complete theme?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions