2016-03-22 53 views
0

我使用ggplot和ggplot.multiplot函數來繪製每頁多點(2列圖),但我無法做到這一點。請幫助如何在單個PDF中繪製多頁(兩列圖)每頁?

我有一個ggplots在變量plot_list中的列表,並使用函數ggplot2.multiplot繪製每頁2個圖。但它會在一頁中繪製出所有數字。我想在單個圖中每頁有兩個圖。

>plot_list ## ggplot saved in a list though i have long list to plot 
[[1]] 

[[2]] 

[[3]] 

[[4]] 

在這兩種情況下,我試過,但所有四個地塊在同一頁上畫在:

library(easyGgplot2) 
library(ggplot2) 
ggplot2.multiplot(plotlist = plot_list, cols=2) 
ggplot2.multiplot(plotlist = plot_list) 

但是其作爲工作:

ggplot2.multiplot(plot_list[[1]],plot_list[[2]],cols=2) 
ggplot2.multiplot(plot_list[[3]],plot_list[[4]],cols=2) 

但我有數字來產生一長串一個pdf!

我也試過library("cowplot"),但在使用數字列表時出錯。

plot_grid(plot_list, ncol = 2, nrow = 1) 

Error in ggplot_to_gtable(x) : 
    Argument needs to be of class "ggplot" or "gtable" 

請大家幫忙。 感謝

+0

你打算使用par(mfrow = c(2,2))來繪製你想要繪製的四個地塊嗎? 另外,一些grid.arrange函數也可能會在這裏實現。 – InfiniteFlashChess

+0

請參閱此鏈接瞭解我所談論的內容。 http://www.statmethods.net/advgraphs/layout.html – InfiniteFlashChess

+0

你從哪裏得到那個'ggplot.multiplot'函數?此外:包含[可重現的示例]總是很好的(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610)。 – Jaap

回答

2

gridExtra::marrangeGrob

library(ggplot2) 
library(gridExtra) 

pl <- replicate(5, ggplot(), simplify=FALSE) 
ml <- marrangeGrob(pl, nrow=1, ncol=2) 
ggsave("multipage.pdf", ml) 

enter image description here

相關問題