jrnold / ggthemes

Additional themes, scales, and geoms for ggplot2
http://jrnold.github.io/ggthemes/
1.32k stars 227 forks source link

Plot with `theme_fivethirtyeight()` applied can't be further modified with `{ggplot2}` functions #138

Closed IndrajeetPatil closed 2 years ago

IndrajeetPatil commented 2 years ago
library(ggplot2)
library(ggthemes)

p <- ggplot(mtcars, aes(cyl, mpg)) + geom_point() 

# works
p + 
  theme_economist() +
  scale_y_continuous(name = "main", sec.axis = dup_axis(name = "secondary"))


# works
p + 
  theme_gdocs() +
  scale_y_continuous(name = "main", sec.axis = dup_axis(name = "secondary"))


# doesn't work
p + 
  theme_fivethirtyeight() + 
  scale_y_continuous(name = "main", sec.axis = dup_axis(name = "secondary"))

Created on 2022-04-16 by the reprex package (v2.0.1)

KayleeDavisGitHub commented 2 years ago

I think this is intended given the axis.text = element_text(), present in the fivethrityeight code. Other themes do not have the element blank as you mentioned, but some themes have axis tick marks blank, titling blank, and other stuff too. For instance, in economist.R you are unable to adjust the panel.border due to the designer setting that blank.

I'm not sure if this is a bug; I think it's an intended feature to keep the themes close to their source (FiveThirtyEight notoriously rarely ever adds axis labels).

Also wanted to show that this isn't a dual-axis issue or an issue in how you've labeled the axis here, no titling functions work when using that theme for intended purposes:

library(ggplot2)
library(ggthemes)
p <- ggplot(mtcars, aes(cyl, mpg)) + geom_point() 

# works
p + 
  theme_economist() +
  labs(y = "test",
         x = "test")

# works
p + 
  theme_gdocs() +
  labs(y = "test",
         x = "test")

# doesn't work
p +
  theme_fivethirtyeight() +
  labs(y = "test",
         x = "test") +
  xlab("test") + # These don't work either:
  ylab("test")
IndrajeetPatil commented 2 years ago

I'm not sure if this is a bug; I think it's an intended feature to keep the themes close to their source (FiveThirtyEight notoriously rarely ever adds axis labels).

@KayleeDavisGitHub Thanks for the detailed explanation! Makes sense then that this doesn't work.

KayleeDavisGitHub commented 1 year ago

Happy to help @IndrajeetPatil ❤️ Thanks for all the work you've done for the R community!

For completeness here are some other resources if people are interested: