[R] win.metafile() problem -- possible bug?

Schwarz, Paul paul.schwarz at oregonstate.edu
Mon Oct 20 22:23:32 CEST 2003


As a followup to a previous posting regarding the win.metafile()
function, I've been having some problems as well.  In my case, I've been
converting some scripts from S-SPLUS to R that create graphs in order to
take advantage of R's plotmath capabilities.

In the sample code shown below, the axis labels display the units for
the data.  In particular, the units for the y axis are "grams carbon per
meter squared per month" or "gC m-2 m-1".  I have noticed that using the
following code, if one prints directly from the graph window, the plot
prints correctly with the proper spacing between the "gC", "m-2", and
"m-1".  However, when I use either the "copy as metafile" feature of the
Windows RGui or add a direct call to win.metafile(), the subsequent .wmf
file does not have spaces between the components of the axis labels.

#win.metafile(filename= "Rplot%02d.emf", height=11, width=8.5,
pointsize=12)
par(mar= c(5,4,4,5)+0.1)

x <- 1:10
y <- 0.8*x+1
plot(x, y, type="n", axes=F, xlab="", ylab="")
box()
points(x, y, pch=1, col=1, cex=1.2)
axis(side=2)
mtext(side=2, line=2.5, expression(paste("monthly (gC ", m^-2, " ",
m^-1, ")")))
axis(side=1, at=1:12)

par(new=T)#, xaxs="d")
plot(x, y, type="n", axes=F, xlab="", ylab="")
y <- 0.5*x-1
points(x, y, pch=16, col=1, cex=1.2)
axis(side=4)
mtext(side=4, line=3, expression(paste("cumulative (gC ", m^-2, ")")))


I have been working with R 1.8.0 on a computer runing Windows XP.
However, I've also tried the code under R 1.7.1, and the behavior
appears to be the same.  Also, the "correct" spacing when printing the
graph window directly does not appear to be related to what kind of
print driver is used because both PostScript and PCL drivers print
correctly.  Moreover, I've also tried to paste the metafile into a
program other than MS Word, but the results are the same as with MS
Word.  So I am guessing that the lack of spaces between the axis label
components is related to the creation of the windows metafile.

A workaround is that an extra space can be added in the call to
expression(), but it certainly would be nice not to need two different
statements that depended on whether the graph was printed directly or
saved as a metafile.

So could this be a bug, or is it some sort of known limitation when
creating metafiles?

Thanks for your time and consideration,

-Paul Schwarz




More information about the R-help mailing list