禁用ggplots的cowplot默认值 [英] Disable cowplot default for ggplots
问题描述
ggplot2
附加软件包 cowplot
对描绘多个名为 plot_grid()
。这里是 plot_grid()
的作用: library(ggplot2);库(cowplot)
plot_a< - ggplot(mtcars,aes(mpg,wt))+ geom_point()
plot_b< - ggplot(mtcars,aes(mpg,disp)) + geom_point()
plot_grid(plot_a,plot_b,labels = c(A,B))
请注意,如何加载 cowplot
更改绘图的默认样式。如何加载 cowplot
包,以便我可以使用 plot_grid()
函数,但也禁用默认打印样式 cowplot
强制执行
theme_gra(theme_gray())事前:
theme_set(theme_gray())
plot_grid (plot_a,plot_b,labels = c(A,B))
=https://i.stack.imgur.com/BAMiw.png>
然后,如果你想疯狂地使用主题,你可以安装 ggthemes
,并简单地用您选择的任何主题替换 theme_gray()
,或者自行滚动。另请参阅这个小插曲,了解各个元素的风格。
The ggplot2
add-on package, cowplot
, has a nice function for plotting multiple plots called plot_grid()
. Here's plot_grid()
in action:
library(ggplot2); library(cowplot)
plot_a <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
plot_b <- ggplot(mtcars, aes(mpg, disp)) + geom_point()
plot_grid(plot_a, plot_b, labels = c("A", "B"))
But note how loading cowplot
changes the default style of plots. How can I load the cowplot
package so that I can use the plot_grid()
function but also disable the default plot styles that cowplot
enforces?
解决方案 Just call theme_set(theme_gray())
beforehand:
theme_set(theme_gray())
plot_grid(plot_a, plot_b, labels = c("A", "B"))
Then, if you want to go crazy with themes, you could install ggthemes
and simply replace theme_gray()
with any theme you choose, or roll your own. Also see this vignette for styling individual elements.
这篇关于禁用ggplots的cowplot默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!