[R] Printing Lattice Graphs from Windows

Charles and Kimberly Maner ckjmaner at carolina.rr.com
Mon Jun 7 05:11:00 CEST 2004


Hi.  This did not work for me per my R output/session below:

> library(lattice)
> win.metafile()
> trellis.par.set('background', list('white'))
> trellis.par.set('plot.symbol',list(cex=0.8, col="blue", font=1, pch=1))
> xyplot(1 ~ 1)
Error in unit(rep(1 * xaxis.cex[1], length(strbar)), "strheight", strbar) : 
        x and units must have length > 0
> dev.off()
null device 
          1 
>  

When I pasted the result into MS Word, I got the same paste--blank.  And,
yes, another default bg color such as "white" or "transparent" would be
great as I am definitely not a fan of the standard "gray" either.  I
researched how to default it to something else, but it seems to have to be
done manually when a lattice/trellis graph is fired up.  Strange, though, as
the standard/base graph/plotting does default to a "white" background.


--Charles

-----Original Message-----
From: Spencer Graves [mailto:spencer.graves at pdf.com] 
Sent: Sunday, June 06, 2004 10:00 PM
To: Duncan Murdoch
Cc: Deepayan Sarkar; r-help at stat.math.ethz.ch; Charles and Kimberly Maner
Subject: Re: [R] Printing Lattice Graphs from Windows

Hi, Duncan: 

      Thanks.  It worked for me, complete with the gray background and
pastel blue dot.  The following also worked to eliminate the (to me
ugly) gray background, etc.: 

win.metafile()
trellis.par.set('background', list('white')) trellis.par.set('plot.symbol',
  list(cex=0.8, col="blue", font=1, pch=1))
xyplot(1 ~ 1)
dev.off()

      Thanks again.  spencer graves

Duncan Murdoch wrote:

>On Sun, 06 Jun 2004 17:43:42 -0700, Spencer Graves 
><spencer.graves at pdf.com> wrote:
>
>  
>
>>Hi, Deepayan: 
>>
>>     Following your suggestion, I tried the following in Rgui.exe: 
>>
>>    
>>
>>>xyplot(1~1)
>>>win.metafile()
>>>graphics.off()
>>>      
>>>
>>     I then switched to MS Word, pasted, and got the same blank plot 
>>as before.  (I actually tried other things as well, but came to this 
>>after reading the documentation.)
>>    
>>
>
>You should open the device *first*.  Then you plot to it, then close it 
>and the graphics are saved.
>
>That is,
>
>  
>
>>library(lattice)
>>win.metafile()
>>xyplot(1 ~ 1)
>>dev.off()
>>    
>>
>
>This worked for me in a single attempt; I haven't tested it thoroughly.
>
>Generally speaking, you get better graphics results by plotting to the 
>final graphics device rather than plotting to the screen and copying 
>somewhere, because the graphics system makes some choices based on the 
>target device capabilities, and those choices might not be appropriate 
>on a different device.  I notice lines are often too thin when printed 
>from a plot on screen, for example.
>
>Duncan Murdoch
>  
>




More information about the R-help mailing list