[R] dev.copy legend problem

Marc Schwartz (via MN) mschwartz at mn.rr.com
Thu Nov 17 18:20:14 CET 2005


On Thu, 2005-11-17 at 17:03 +0100, Florence Combes wrote:
> Dear all,
> 
> We are facing this problem for long, and so ask for your help.
> 
> We are plotting 2 graphs in a postscript device (left part -layout
> function-), and the common legend for these graphs on the right part.
> The legend in the postscript device looks ok: this is color lines with
> numbers on the right (6 columns) , see the code below:
> 
> > nblock<-c(1:48)
> > leg<-paste(c(1:npin)," ",sep=" ")
> > legend(0,19,legend = leg, col=rainbow(nblock), lty=1,
> merge=TRUE,ncol=6,bty="n",cex=0.6)
> 
> The problem we are facing is that we dev.copy to a pdf device and then, the
> legend doesn't look the same: numbers overlap a little lines.

The problem with using dev.copy() is that it can result in slightly (or
notably) different plotting characteristics, which are device dependent.

A plot that is viewed on the screen, for example, may or may not (most
likely not) look the same when created using the same code to a
postscript device or a pdf device. This can be further exacerbated if
the plot device dimensions and pointsizes are not explicitly defined, as
"device shrinkage" may occur. I suspect that this is what you are
experiencing.

If you want to end up with a PDF plot, use pdf() and set the various
plotting parameters (ie. font size, etc.) based upon what you see there,
not what you see on the screen or in another device.

One other possibility, just to throw it out there since you are on
Linux, is to use ps2pdf from a console to convert the PS file to PDF.
This uses Ghostscript to do the conversion and will generally work well,
but testing with your particular plot, given possible issues with fonts,
etc. would still be a good idea. See 'man ps2pdf' for more information.

> Has someone already encountered such a thing ?
> 
> Any help apreciated, thanks a lot.
> 
> Florence.
> 
> ----------------------------------------
> R 2.1.0 on a Linux Debian.

Have not been able to get your SysAdmin to upgrade you yet?

:-)

HTH,

Marc Schwartz




More information about the R-help mailing list