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

David Winsemius dwinsemius at comcast.net
Wed Feb 23 15:14:06 CET 2011


On Feb 23, 2011, at 8:32 AM, Matthieu Stigler wrote:

> Dear Ista
>
> Thanks a  lot for your help! However, when I spedify the right size  
> I wish (the same as specified in par() ) I get an error:
>
> pdf("try.pdf", height=0.5, width=0.3)
>
> par(pin=c(0.5, 0.3),mai=rep(0.1,4), omi=rep(0.01,4), mar=c(5,4,4,2))

Given the size of the margins (determined by fonts and line width  
defaults) the smallest (but still useless) pdf I can create is:

 > pdf("try.pdf", height=2.2, width=1.4)
 > 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()
quartz
      2

You should rethink your strategy and articulate your goals and  
constraints a bit better. I remember a discussion in rhelp of setting  
sizes for graphical files within the last week where the consensus of  
knowledgeable useRs was to make a bigger file and then resize it.

-- 
David.


>
> plot(runif(100))
>
> dev.off()
>
>
> I don't see why my marings now would have become too small ... any  
> idea?
>
> Thanks!!
>
>
> Le 23. 02. 11 14:22, Ista Zahn a écrit :
>> It should be specified in pdf() as you did. If you try
>>
>> pdf("try.pdf", height=2, width=2)
>>
>> 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()
>>
>> I think the problem will become apparent.
>>
>> best,
>> Ista
>>
>> On Wed, Feb 23, 2011 at 12:39 PM, Matthieu Stigler
>> <matthieu.stigler at gmail.com>  wrote:
>>> Dear R List
>>>
>>> Could I ask again my question about where the size of a plot  
>>> should be
>>> specified (in par or pdf?). I still did not figure out, and any  
>>> help would
>>> be much appreciated!!
>>>
>>> Thanks a lot!
>>>
>>> Matthieu
>>>
>>> Le 22. 02. 11 13:53, Matthieu Stigler a écrit :
>>>> 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
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list