繁体   English   中英

有没有办法调整牛图对象的主题?

[英]is there a way to adjust theme of a cowplot object?

我可以更改组合情节的主题吗?

例子:

library(ggplot2)
library(cowplot)
p1 = ggplot(diamonds, aes(x = price)) + geom_histogram(bins = 30)
p2 = ggplot(diamonds, aes(x = table)) + geom_histogram(bins = 30)
p = cowplot::plot_grid(p1,p2)

这有效:

p1 + theme_bw()

这不起作用:

p + theme_bw()

最简洁的答案是不”。

您在牛图中看到的图已经被渲染为格罗布。 它们没有您可以更改的主题元素。 从理论上讲,您可以“深入”到 p 结构中埋藏的 grob 并一次更改单个 grob,但这很困难、混乱且不可靠。

作为展示它有多棘手的练习,以下是将p更改为theme_bw外观的方法:

p

在此处输入图片说明

p$layers <- lapply(p$layers, function(x) {
  y <- x$geom_params[[1]][[1]][[6]][[4]][[1]][[4]]
  y[[1]][[9]]$fill <- "white"
  y[[1]][[9]]$col <- "black"
  y[[4]][[7]]$col <- "gray90"
  y[[5]][[7]]$col <- "gray90"
  y[[2]][[7]]$col <- "gray90"
  y[[3]][[7]]$col <- "gray90"
  x$geom_params[[1]][[1]][[6]][[4]][[1]][[4]] <- y
  x
})

p

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM