[R] Set size of plot: in pdf() or par() ?

Matthieu Stigler matthieu.stigler at gmail.com
Tue Feb 22 13:53:03 CET 2011


Hi

I want to have a rectangular plot of size 0.5*0.3 inches. I am having 
surprisingly a difficult time to do it... Since I will export it, I use 
also pdf(). The plot works fine, but once I specify the size in pdf() I 
get problems... see:

Say I specify my plot as following:

par(pin=c(0.5, 0.3),mai=rep(0.1,4), omi=rep(0.01,4), mar=c(5,4,4,2))

plot(runif(100))


If I now add

pdf()

par(pin=c(0.5, 0.3),mai=rep(0.1,4), omi=rep(0.01,4), mar=c(5,4,4,2))

plot(runif(100))

dev.off()


The resulting pdf has not the size specified!

If I specifz this size in pdf(), I get an error...

pdf("try.pdf", height=0.3, width=0.5)

par(pin=c(0.5, 0.3),mai=rep(0.1,4), omi=rep(0.01,4), mar=c(5,4,4,2))

plot(runif(100))

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


So obviously pdf() is modifying some other par() parameter I could not 
figure out... Any idea?

Thanks!!

Matthieu



More information about the R-help mailing list