背景
我想更改ggplot使用的主题,但我很难理解theme_update()
文档和示例。
我正在使用align_plots()
将箱线图放置在密度图上,但我发现代码中没有任何内容会导致错误,并且只剩下最小的示例。我怀疑错误是由theme_blank()
的使用引起的,但我不确定为什么会发生这种情况,也不知道如何修复它。
因此,我提供一个最小可重现的示例,展示我的错误:
library(ggExtra)
align.plots(qplot(1))
但是在我更新主题后,它就出故障了:
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))
这会出现错误:
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
问题:
这个错误是什么原因引起的?
在使用
?theme_update()
时,我在ggplot文档中找到了一些信息,但在ggplot网站上找不到答案,尽管我最接近的答案是polishing.r脚本。
注意:
我按照另一个问题的Hadley的建议得到了相同的错误。
opt <- opts(...)
align.plots(qplot(1) + opt)
其中...
是上面theme_update()
的内容
theme_grey()
而不是在newtheme
中提供的theme_blank()
选项。 - David LeBauertheme_set(theme_grey())
。 - Anton K