Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Error in plot.new() : figure margins too large"

Tags:

plot

r

png

In R, I met a running error as follows:

> png("p3_sa_para.png", 4, 2)
> par(mfrow=c(1,2))
> plot(c(1:10), ylab="Beta",xlab="Iteration")
Error in plot.new() : figure margins too large
> plot(c(1:10), ylab="Gamma",xlab="Iteration")
Error in plot.new() : figure margins too large
> dev.off()
X11cairo 
       2 

I have already made the image size small to be 4 by 2, why it still complains "figure margins too large"? How can I solve this problem with png?

It is strange that if I change png to pdf, then it will work. I also wonder why?

Thanks and regards!

like image 377
Tim Avatar asked Dec 10 '10 15:12

Tim


2 Answers

The png() function uses pixels not inches, so try something like

png("p3_sa_para.png", 640, 480)

And to answer your second question, yes, pdf() uses inches because a vector-graphics format has no notion of pixels. The help(png) and help(pdf) functions are your friends.

like image 194
Dirk Eddelbuettel Avatar answered Oct 23 '22 02:10

Dirk Eddelbuettel


The problem can simply arise from using a certain IDE. I was using Rstudio, and I got a slew of errors. My exact same code worked fine in the console.

like image 31
RMurphy Avatar answered Oct 23 '22 02:10

RMurphy