Itay Furman
2004-Jan-15 07:08 UTC
[R] Legend text -- discrepancy between X11 and postscript
Hi, When I place a legend on a plot it looks exactly as I intended on the screen. However, almost always, when I export this to postscript file, the legend's text protrudes through the legend's frame (the latter being placed correctly). See the appended example code. I can send the EPS file as well for those that are interested (<4 kb; <200 lines). I found nothing in the FAQS, or in R-intro to enlighten me. I tried few things --- changing font size, setting legend's text width, etc. --- but eventually gave up. How can I get a consistent X11 and PS rendering? (R 1.8.1 on Linux RedHat 9; GhostView 3.5.8) TIA Itay #### Example for X11-EPS discrepancy in legend rendering #### ## A useless data to plot x <- 0:10; XY <- list(x=x, y=2*x) ## Set lims explicitly; use later in placing the legend. xlim <- range(XY$x); ylim <- range(XY$y) plot(XY, xlim=xlim, ylim=ylim, type="l", lty=1, col=2, axes=FALSE) axis(1); axis(2) ## Legend and plot share the bottom-right corner. legend(xlim[2], ylim[1], "A set of random numbers", lty=1, col=2, xjust=1, yjust=0) ## On the screen: OK. Now produce EPS file. dev.copy2eps(file="test.eps", paper="letter") ######################### End example ################## -- itayf at fhcrc.org
Philipp Pagel
2004-Jan-15 08:07 UTC
[R] Legend text -- discrepancy between X11 and postscript
Hi! On Wed, Jan 14, 2004 at 11:08:44PM -0800, Itay Furman wrote:> When I place a legend on a plot it looks exactly as I intended > on the screen. However, almost always, when I export this to > postscript file, the legend's text protrudes through the legend's > frame (the latter being placed correctly).This routinely happens to me when using dev.copy2eps. If I use a postscript device to begin with everything is fine. cu Philipp -- Dr. Philipp Pagel Tel. +49-89-3187-3675 Institute for Bioinformatics / MIPS Fax. +49-89-3187-3585 GSF - National Research Center for Environment and Health Ingolstaedter Landstrasse 1 85764 Neuherberg, Germany
Prof Brian Ripley
2004-Jan-15 08:25 UTC
[R] Legend text -- discrepancy between X11 and postscript
The short answer is not to copy the device, but to replot on the new device. That is the advice given in MASS, for example. When you copy a device, you replay the device list and hence the lines and text are placed at the positions calculated using the font metrics of the first device and not the second. dev.copy2eps does not try to adjust the pointsize of the postscript device, and provided the fonts match you should just be able to adjust the pointsize in this case. You do need to be suspicious of on-screen viewers and indeed of ghostscript, for they are often not pixel-perfect and ghostscript does font substitution (it does not have Helvetica). I would always test by printing on a postscript printer. On Wed, 14 Jan 2004, Itay Furman wrote:> > Hi, > > When I place a legend on a plot it looks exactly as I intended > on the screen. However, almost always, when I export this to > postscript file, the legend's text protrudes through the legend's > frame (the latter being placed correctly). > See the appended example code. I can send the EPS file as well > for those that are interested (<4 kb; <200 lines). > > I found nothing in the FAQS, or in R-intro to enlighten me. I > tried few things --- changing font size, setting legend's text > width, etc. --- but eventually gave up. > > How can I get a consistent X11 and PS rendering? > > (R 1.8.1 on Linux RedHat 9; GhostView 3.5.8) > > TIA > Itay > > #### Example for X11-EPS discrepancy in legend rendering #### > > ## A useless data to plot > x <- 0:10; XY <- list(x=x, y=2*x) > > ## Set lims explicitly; use later in placing the legend. > xlim <- range(XY$x); ylim <- range(XY$y) > > plot(XY, xlim=xlim, ylim=ylim, type="l", lty=1, col=2, axes=FALSE) > axis(1); axis(2) > > ## Legend and plot share the bottom-right corner. > legend(xlim[2], ylim[1], "A set of random numbers", > lty=1, col=2, xjust=1, yjust=0) > > ## On the screen: OK. Now produce EPS file. > dev.copy2eps(file="test.eps", paper="letter") > ######################### End example ################## > > -- > itayf at fhcrc.org > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595