繁体   English   中英

安排多个ggplot2图

[英]Arranging multiple ggplot2 plots

我正在尝试创建大量的图(简单的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)

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

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

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

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

谢谢,-e

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()
}

暂无
暂无

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

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