-
Notifications
You must be signed in to change notification settings - Fork 2k
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
theme(x, y) versus theme(x) + theme(y) #3039
Comments
Perhaps the same issue: To display the axis line, I need to set
|
This is a bug with library(ggplot2)
p1 <- ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme_classic() +
theme(axis.line.x = element_line(color = "blue"),
axis.ticks.x = element_line(color = "red"),
axis.ticks.length = unit(1, "cm"))
p2 <- ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme_classic() +
theme(axis.line.x = element_line(color = "blue")) +
theme(axis.ticks.x = element_line(color = "red")) +
theme(axis.ticks.length = unit(1, "cm"))
cowplot::plot_grid(p1, p2) Created on 2018-12-15 by the reprex package (v0.2.1) |
Actually, while In any case, it's a bug. |
Third time is a charm. I think I've found the real culprit: library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme_void() +
theme(line = element_line(size = 0.5, linetype = 1, lineend = "butt", color = NA)) +
theme(axis.line.x = element_line(color = "blue")) +
theme(axis.ticks.x = element_line(color = "red")) +
theme(axis.ticks.length = unit(1, "cm")) Created on 2018-12-15 by the reprex package (v0.2.1) This still means |
Thanks for the feedback and sleuthing Claus! I suspect No problem that I can see with Not sure about library(reprex)
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme_light() +
theme(axis.line.x = element_line(color = "blue")) +
theme(axis.ticks.x = element_line(color = "red")) +
theme(axis.ticks.length = unit(1, "cm")) Created on 2018-12-16 by the reprex package (v0.2.1) |
There seem to be multiple issues at play here. There clearly is a difference between library(ggplot2)
p1 <- ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme_light() +
theme(axis.line.x = element_line(color = "blue")) +
theme(axis.ticks.x = element_line(color = "red")) +
theme(axis.ticks.length = unit(1, "cm"))
p2 <- ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme_light() +
theme(axis.line.x = element_line(color = "blue"),
axis.ticks.x = element_line(color = "red"),
axis.ticks.length = unit(1, "cm"))
cowplot::plot_grid(p1, p2) Created on 2018-12-15 by the reprex package (v0.2.1) |
The fundamental problem here is that adding themes to the plot object doesn't behave the same as adding themes to each other and seems buggy. Specifically, adding additional theme elements seems to convert parts of an incomplete theme into parts of a complete theme in the plot building process. library(ggplot2)
t1 <- theme_light() +
theme(axis.line.x = element_line(color = "blue")) +
theme(axis.ticks.x = element_line(color = "red"))
t2 <- theme_light() +
theme(axis.line.x = element_line(color = "blue"),
axis.ticks.x = element_line(color = "red"))
identical(t1, t2)
#> [1] TRUE
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
p1 <- p + theme_light() +
theme(axis.line.x = element_line(color = "blue")) +
theme(axis.ticks.x = element_line(color = "red"))
p2 <- p + theme_light() +
theme(axis.line.x = element_line(color = "blue"),
axis.ticks.x = element_line(color = "red"))
identical(p1$theme, p2$theme)
#> [1] FALSE
p1$theme$axis.line.x$inherit.blank # incorrect
#> [1] TRUE
p2$theme$axis.line.x$inherit.blank # correct
#> [1] FALSE
p1 p1$theme$axis.line.x$inherit.blank <- FALSE
p1 Created on 2018-12-15 by the reprex package (v0.2.1) |
I've tracked it down. When themes are added to the plot the function that is used is Lines 103 to 105 in 9292832
But when two themes are added together directly, the function is Line 51 in 868fdb7
The two functions have different logic, because Lines 470 to 493 in 442108d
I think the right logic would be to first add all the theme parts together with |
I think we agree this is a bug. How can I add a "bug" label to this issue? Do I need special rights or have I missed the icon on which to click? Currently it says "Labels: 'None yet'". Thanks. |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
I had always assumed that the following were equivalent. They are not. Is it a feature of theming that all the options must be set in
theme()
in one pass?If so, may I suggest adding an example like below to: https://ggplot2.tidyverse.org/reference/theme.html
Created on 2018-12-15 by the reprex package (v0.2.1)
Created on 2018-12-15 by the reprex package (v0.2.1)
The text was updated successfully, but these errors were encountered: