R中的一个PDF页面上的多个hexbin图 [英] several hexbin plots on one PDF page in R

查看:215
本文介绍了R中的一个PDF页面上的多个hexbin图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个包含许多hexbin个图的PDF,我希望每页具有特定数量的图.

I'm trying to create a PDF with a number of hexbin plots where I'd like to have a particular number of plots per page.

此作品有效:

PDFPath = "C:\\temp\\some.pdf"
pdf(file=PDFPath)  
par(mfrow = c(2,2))
for (i in seq(5,10))   
{    
  VAR1 = rnorm(i)  
  VAR2 = rnorm(i)  
  plot(VAR1, VAR2)
} 
dev.off() 

这是行不通的.每页只生成一个图:

This one doesn't work. It only generates one plot per page:

library(hexbin)
PDFPath = "C:\\temp\\some.pdf"
pdf(file = PDFPath)  
par(mfrow = c(2,2))
for (i in seq(5,10))   
{     
  VAR1 = rnorm(i)  
  VAR2 = rnorm(i)  
  plot(hexbinplot(VAR1 ~ VAR2))
} 
dev.off() 

有什么问题的想法吗?

我刚刚注意到,原因是mfrow仅指基础图形,而不指网格图形.有没有办法为hexbin获得相似的结果?

I've just noticed that the reason is that mfrow only refers to base graphics and not to grid graphis. Is there a way to achieve similar results for hexbin?

推荐答案

使用grid.arrange:

library(hexbin)
plotList <- lapply(1:4, function(i) {
  VAR1 = rnorm(i*100)  
  VAR2 = rnorm(i*100)  
  hexbinplot(VAR1 ~ VAR2)
})

library(gridExtra)    
do.call(grid.arrange, c(plotList, ncol=2))

这篇关于R中的一个PDF页面上的多个hexbin图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆