【发布时间】:2018-10-05 13:15:24
【问题描述】:
我需要使用cowplot 为以下多个绘图图形添加一个 x 标签和一个 y 标签:
library(ggplot2
set.seed(99)
x_1 = data.frame(z = rnorm(100))
x_2 = data.frame(z = rnorm(100))
x_3 = data.frame(z = rnorm(100))
lst = list(x_1, x_2, x_3)
lst_p = list()
for (i in 1:length(lst)) {
lst_p[[i]] = ggplot(data=lst[[i]], aes(lst[[i]]$z)) +
geom_histogram() +
xlab("X LAB") +
ylab("Y LAB")
}
p_no_labels = lapply(lst_p, function(x) x + xlab("") + ylab(""))
title = cowplot::ggdraw() + cowplot::draw_label("test", size = 20)
p_grid = cowplot::plot_grid(plotlist = p_no_labels, ncol = 1)
print(cowplot::plot_grid(title, p_grid,
ncol = 1, rel_heights = c(0.05, 1, 0.05)))
x 标签应该在底部,y 标签应该在左边。
有什么快速的方法吗? 谢谢
【问题讨论】:
-
这是一个相关的问题:stackoverflow.com/questions/49577461/…
标签: r ggplot2 label add cowplot