Histogram, error: Error in plot.new() : figure margins too large [duplicate]
Asked Answered
C

2

6

I have to plot 141 histograms in R. I am working with windows 8. then I write:

par(mfcol=c(12,12), oma=c(1,1,0,0))

for(m in 1:141 ){
  x <- precData[[m]]
  hist(x[x != 0],30, xlab=NA, ylab=NA, main=statData$Name[m])
}

But always I get this error: Error in plot.new() : figure margins too large

How can I solve it?? Is there any command for adjusting the size of each histogram??

Thanks.

Comber answered 27/12, 2013 at 13:40 Comment(3)
Any of these help? #12766666Runin
Do you happen to be using RStudio?Whereby
No, it does not help me...Comber
I
6

You set the outer margins (outside the whole set of plots) but the inner margins (for each panel) are at the default. With the margins at the default, there is not enough room within each panel to plot the histogram and have the marginal information.

So you need to change the inner margins as well, and if you want anything to look reasonable then you should also change size and position of the things to be added.

Here is an example (I had to change to random data since your example was not reproducible):

par(mfcol=c(12,12), oma=c(1,1,0,0), mar=c(1,1,1,0), tcl=-0.1, mgp=c(0,0,0))

for(m in 1:141 ){
  x <- rnorm(100)
  hist(x[x != 0],30, xlab=NA, ylab=NA, main=paste('data: ',m), 
        cex.axis=0.5, font.main=1, cex.main=0.8)
}
Intemerate answered 27/12, 2013 at 18:19 Comment(0)
B
13

If it occurs using RStudio, you could try to enlarge your plot window. Sometimes it helps.

But answered 27/12, 2013 at 15:17 Comment(3)
Yeah, I tried to enlarge it, but it doesnt help, because it is many histograms: 141 hists.Comber
That's what I was going to suggest. I had the same problem a few weeks ago and the solution for me was to enlarge the plot window.Whereby
Keep resizing plot window is annoying. Is there any one who knows a better way?Unstriped
I
6

You set the outer margins (outside the whole set of plots) but the inner margins (for each panel) are at the default. With the margins at the default, there is not enough room within each panel to plot the histogram and have the marginal information.

So you need to change the inner margins as well, and if you want anything to look reasonable then you should also change size and position of the things to be added.

Here is an example (I had to change to random data since your example was not reproducible):

par(mfcol=c(12,12), oma=c(1,1,0,0), mar=c(1,1,1,0), tcl=-0.1, mgp=c(0,0,0))

for(m in 1:141 ){
  x <- rnorm(100)
  hist(x[x != 0],30, xlab=NA, ylab=NA, main=paste('data: ',m), 
        cex.axis=0.5, font.main=1, cex.main=0.8)
}
Intemerate answered 27/12, 2013 at 18:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.