Paul Johnson
2009-Jan-27 07:13 UTC
[R] How do you specify font family in png output; png cross-platform issues
For teaching purposes, I prepared a little R program. I want to give this to students who can run it and dump out many formats and then compare their use in LaTeX documents. I do not have too much trouble with xfig or postscript format, but I've really run into a roadblock where png files are concerned. My original problem was that the png device does not accept a family option. How can I have png output with the "Times" family to compare with the postscript or pdf output? While searching for information on this, I discovered there have been a lot of R changes in png support. If I give this script to people with Mac or Windows, what are the chances that it will work? If I'm reading the png help page correctly, there are different types available, Xlib and cairo, but I don't understand what all that means for sending a program like this across systems. (fear the worst, but ask hoping for best). As far as I understand it, the paper="special" option is needed so that the eps or pdf output will fit into a document without creating really huge margins around the graph. Correct? x<- rnorm(333) y<- rnorm(333) plot ( x,y, xlab="Input Variable", ylab="Output Variable") xfig(file="testplot.fig", horizontal=F, height=6, width=6, family="Times") plot ( x,y, xlab="Input Variable", ylab="Output Variable") dev.off() postscript(file="testplot-1.eps", horizontal=F, height=6, width=6, family="Times", onefile=F, paper="special") plot ( x,y, xlab="Input Variable", ylab="Output Variable") dev.off() postscript(file="testplot-2.eps", horizontal=F, height=4, width=4, family="Times", onefile=F, paper="special") plot ( x,y, xlab="Input Variable", ylab="Output Variable") dev.off() pdf(file="testplot-1.pdf", height=6, width=6, family="Times",onefile=F,paper="special") plot ( x,y, xlab="Input Variable", ylab="Output Variable") dev.off() png(file="testplot-1.png", height=350, width=550, type="Xlib") plot ( x,y, xlab="Input Variable", ylab="Output Variable") dev.off() png(file="testplot-2.png", height=350, width=550, type="cairo") plot ( x,y, xlab="Input Variable", ylab="Output Variable") dev.off() =========================================== Can I bother you about one last png issue? While searching r-help, I see posts about the difference in png output between type Xlib and cairo. For reasons I do not understand, ordinary viewers like GQview or Firefox make cairo-produced png files look "blurry" (in the words of posts on r-help). The png output from type="Xlib" output is not blurry. This raises another level of confusion about this exercise I'm devising. Does R for Windows, as provided on the CRAN system, use "Xlib" for png? pj -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas
Possibly Parallel Threads
- Problems with graphical devices, e.g., png(), pdf(): blurry graphical output
- patch for textspecial and defaultfont in xfig
- Re: Bug#213857: r-base-core: xfig plot fails with invalid line type (PR#4401)
- beta symbol cut off in y axis label using jpeg/png/tiff
- Source code for R graphics devices