Closed basille closed 7 years ago
Hello,
I don't really have the time to look into this in detail right now, but I'm quite certain that the problem is the same as issue #60, which is a bug in ggplot2
's theme_void()
. Could you investigate, and maybe try a workaround similar to the one I posted in issue #60? And also, if it turns out to be a ggplot2
bug, file a report there?
Thanks!
Thanks, I will try to investigate. At first glance, I'm not sure it's related, but I need to understand ggplot2 (and theming) mechanisms better before I can reach any conclusion. I'll keep you posted!
Here's how you test this: Load only ggplot2, set the theme with theme_update, make a plot, and then call the plot + theme_void(). If the grid doesn't go away then you know that theme_void() has a bug. It should undo your theme_update.
Thank you for your guidance. I think I start to see it more clearly… I now have a minimal reproducible example using just ggplot2:
library(ggplot2)
qplot(1:10, (1:10)^2) # Basic plot
theme_update(panel.grid.major = element_line(colour = "red",
size = 0.5)) # I want major grid in red
qplot(1:10, (1:10)^2) # Works OK
qplot(1:10, (1:10)^2) + theme_void() # Grid still here
But before I submit an issue, I'd like to be sure I understand correctly: Are we talking about a bug per se, or a limitation of ggplot2::theme_void
which does not set panel.grid(.major/minor)
to element_blank()
?
Following your answer on #60, a workaround is:
assignInNamespace("theme_nothing", function(){
theme_void() +
theme(panel.grid.major = element_blank())
}, "cowplot")
I think it's a bug in ggplot2::theme_void
, or alternatively in the ggplot2
theming mechanism in general. theme_void
bills itself as a complete theme, which means that it should override all prior theme settings. However, that doesn't happen, as you can see from these examples.
I just posted bug #2079 on ggplot2 issue tracking system. I'll keep you posted!
Thanks for helping me investigate, and finding a temporary workaround!
I've decided to reimplement theme_nothing()
since this problem still isn't resolved for base ggplot2. Code is in the current development branch on github.
library(ggplot2)
qplot(1:10, (1:10)^2) # Basic plot
theme_update(panel.grid.major =
element_line(colour = "red", size = 0.5)) # I want major grid in red
qplot(1:10, (1:10)^2) # Works OK
qplot(1:10, (1:10)^2) + theme_void() # Grid still here
library(cowplot)
qplot(1:10, (1:10)^2) + theme_nothing() # Grid now gone
Thanks Claus for taking care of this!
In general, I really like the minimalistic theme settings of cowplot. However, I also like having the major grid, and I find it easier to set it up globally at the beginning of my scripts. It works fine for single plots, but seems to confuse
plot_grid
, which plots a grid on top of the grid plot (and not only on top of single plots).Here is a better explanation with simple iris plots:
This works perfectly. I can use
background_grid
to add the grid manually to each plot:Still works as expected. Now if I update the theme to add the major grid to all plots:
I get the additional grid on top of the combined plot. I didn't attach a picture of it, so please let me know if it's only happening on my computer (note: using Debian Testing, with R 3.3.2, ggplot 2.2.1 and cowplot 0.7.0).
Thanks for looking at this issue!