安排多个ggplot2图

Eco*_*ium 4 r ggplot2

我正在尝试创建大量的图(简单的xy条形图),我想以网格的形式显示.当我使用gridExtra包的grid.arrange时,随着绘图数量的增加,每个单独的绘图都会缩小.有没有办法创建绘图画布,使其跨越多个页面而不缩小每个单独的绘图?

gridExtra的一个简单示例:

require(ggplot2)
require(gridExtra)
plots = lapply(1:50, function(.x) qplot(1:10,rnorm(10),main=paste("plot",.x)))
do.call(grid.arrange,  plots)
Run Code Online (Sandbox Code Playgroud)

上面的代码生成了50个图,但它们缩小了以适应画布.有没有办法避免这种情况?即,让它们跨越多个页面,每个页面将有约9个左右的情节?我对PNG或PDF文件格式没问题.

在尝试grid.arrange之前,我使用了来自此站点的代码示例:http://gettinggeneticsdone.blogspot.com/2010/03/arrange-multiple-ggplot2-plots-in-same.html 并遇到了同样的问题.

我还没有尝试将不同的数据帧组合成一个带有绘图标识符的巨型数据帧.然后我正在考虑使用情节标识符进行分区,但我不确定它是否也会出现缩小每个情节的相同问题.

希望我的问题很明确......

谢谢,-e

Eco*_*ium 8

library(gridExtra)
library(ggplot2)
my_func = function (d,filename = "filename.pdf") {
    pdf(filename,width=14) # width = 14 inches
    i = 1
    plot = list() 
    for (n in names(d)) {
        ### process data for plotting here ####
        plot[[i]] = qplot(x, y, geom="bar", data = my_data,)
        if (i %% 9 == 0) { ## print 9 plots on a page
            print (do.call(grid.arrange,  plot))
            plot = list() # reset plot 
            i = 0 # reset index
        }
        i = i + 1
    }
    if (length(plot) != 0) {  ## capture remaining plots that have not been written out
        print (do.call(grid.arrange,  plot))
    }
    dev.off()
}
Run Code Online (Sandbox Code Playgroud)