문제

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.

This one works:

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

Any ideas on what's going wrong?

EDIT:

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?

도움이 되었습니까?

해결책

Use 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))

enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top