[英]Arranging multiple ggplots in the plot window
I have multiple ggplots and want to arrange them in the plot window in a rectangular fashion.我有多个ggplots ,想以矩形方式将它们排列在 plot window 中。 Below is my code
下面是我的代码
library(ggplot2)
library(ggpubr)
plot1 = ggplot(data.frame(x = 1:3, y = 4:6), aes(x = x, y = y)) + geom_line()
plot2 = ggplot(data.frame(x = 1:3, y = 4:6), aes(x = x, y = y)) + geom_line()
plot3 = ggplot(data.frame(x = 1:3, y = 4:6), aes(x = x, y = y)) + geom_line()
ggarrange(plot1, plot2, plot3, ncol = 2, nrow = 2, align = 'h')
I am getting below arrangement我得到低于安排
I am wondering if the 3rd plot can be placed in the middle of the plot window?我想知道是否可以将第 3 个 plot 放在 plot window 的中间?
Any pointer will be very helpful.任何指针都会非常有帮助。
I adapted code from http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/81-ggplot2-easy-way-to-mix-multiple-graphs-on-the-same-page/我改编了http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/81-ggplot2-easy-way-to-mix-multiple-graphs-on-the-same-中的代码页/
The first option puts one plot on top and two on bottom, second option puts 2 on top and one on bottom.第一个选项将一个 plot 放在顶部,两个放在底部,第二个选项将 2 放在顶部,一个在底部。
Hope this helps - check out the webpage for further options.希望这会有所帮助 - 查看网页以获取更多选项。
library(ggplot2)
library(ggpubr)
plot1 = ggplot(data.frame(x = 1:3, y = 4:6), aes(x = x, y = y)) + geom_line()
plot2 = ggplot(data.frame(x = 1:3, y = 4:6), aes(x = x, y = y)) + geom_line()
plot3 = ggplot(data.frame(x = 1:3, y = 4:6), aes(x = x, y = y)) + geom_line()
ggarrange(plot1,
ggarrange(plot2, plot3, ncol = 2, labels = c("plot2", "plot3")),
nrow = 2,
labels = "plot1"
)
library("cowplot")
ggdraw() +
draw_plot(plot1, x = 0, y = .5, width = .5, height = .5) +
draw_plot(plot2, x = .5, y = .5, width = .5, height = .5) +
draw_plot(plot3, x = 0, y = 0, width = 1, height = 0.5) +
draw_plot_label(label = c("plot1", "plot2", "plot3"), size = 15,
x = c(0, 0.5, 0), y = c(1, 1, 0.5))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.