Background
I would like to change the theme that ggplot uses, but I am having difficulty understanding the theme_update()
documentation and examples.
I am using align_plots()
to place a boxplot over a density plot, but I found none of that code was causing the error, and was left with the minimal example. I suspect that the error is caused by the use of theme_blank()
, but I am not sure why it occurs or how I can fix it.
So, here I provide a minimal reproducible example of an error that I am getting:
library(ggExtra)
align.plots(qplot(1))
But it breaks after I update the theme:
newtheme <- theme_update(axis.text.y = theme_blank(),
axis.line = theme_blank(),
axis.title.x = theme_blank(),
axis.title.y = theme_blank(),
axis.ticks.x = theme_blank(),
panel.grid.major = theme_blank(),
panel.grid.minor = theme_blank(),
panel.border = theme_blank(),
axis.color.y = 'white')
align.plots(qplot(1))
This gives the error:
Error in UseMethod("validGrob") :
no applicable method for 'validGrob' applied to an object of class "NULL"
In addition: Warning message:
In editThisGrob(grob, specs) : Slot 'vp' not found
Questions:
What causes this error?
Where can I get more information on using
?theme_update()
? I got this far on the ggplot documentation, and can't find the answer at the ggplot website, although the closest that I got was the polishing.r script
note:
I get the same error with a solution based on Hadley's suggestion for another question.
opt <- opts(...)
align.plots(qplot(1) + opt)
where ...
is the contents of theme_update()
above