Skip to content
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

axis.title.x overrides axis.title in theme() #3841

Closed
mfherman opened this issue Feb 27, 2020 · 2 comments
Closed

axis.title.x overrides axis.title in theme() #3841

mfherman opened this issue Feb 27, 2020 · 2 comments

Comments

@mfherman
Copy link

This appears to be new behavior in 3.3.0, where if you add a "more specific/child" theme element to a plot, and then also modify the "parent" theme element, the "child" element theme setting is used. This seems like something related to #3039, and I'm not sure if the old behavior was just a bug (that I happened to make use of!).

As an example, the below code returns the same plot with 3.3.0, but in older versions, the first code would remove the x-axis title.

library(ggplot2)

ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
  geom_point() +
  theme(axis.title.x = element_text(size = 16)) +
  theme(axis.title = element_blank())

ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
  geom_point() +
  theme(axis.title = element_blank()) +
  theme(axis.title.x = element_text(size = 16))

Created on 2020-02-27 by the reprex package (v0.3.0)

@clauswilke
Copy link
Member

The old behavior was broken. If you want to inherit from blank elements, you have to explicitly turn this on. (The assumption is that if you're explicitly setting a child element, you actually want it set, not removed.)

library(ggplot2)

ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
  geom_point() +
  theme(axis.title.x = element_text(size = 16, inherit.blank = TRUE)) +
  theme(axis.title = element_blank())

Created on 2020-02-27 by the reprex package (v0.3.0)

@mfherman
Copy link
Author

Thanks for the clarification and all your work on ggplot and other amazing packages!

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

No branches or pull requests

2 participants