[R] Troubles in plotting to a postscript file (not to png)

Paul Murrell paul at stat.auckland.ac.nz
Mon Dec 6 22:07:17 CET 2010


I think the problem is that the viewer you are using for the PS file 
cannot find the ComputerModern fonts that are referenced in the PS file. 
  If you use something like ghostscript to process the file you can see 
this happening ...

[pmur002 at stat18 Temp]$ gs plot_example.ps
ESP Ghostscript 815.02 (2006-04-19)
Copyright (C) 2004 artofcode LLC, Benicia, CA.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Can't find (or can't open) font file 
Can't find (or can't open) font file CMR10.
Querying operating system for font files...
Didn't find this font on the system!
Substituting font Courier for CMR10.

... and if your viewer is having this problem, it probably solves it in 
the same way, by substituting a different font, which will result in 
missing characters, wrong character widths, etc and produce the sort of 
carnage that you are seeing.

The "ComputerModern" font family and the "TeXtext.enc" encoding are very 
special cases set up for only the PostScript device and designed to be 
used for including a figure in a LaTeX document (see the section on "TeX 
fonts" in the help page ?postscript).  Your plot_example.ps file can be 
used successfully in this way.  For example, if you create the following 
simple latex doc ...


... and process that with ...

latex test.tex

... and then process the resulting .dvi with ...

dvips -o test.ps -j0 test.dvi

... then the resulting postscript file, test.ps, has the fonts all 
correctly embedded and there are no missing characters and no nasty 
overlaps (I can send you the test.ps that I produced directly if you like).

So in summary, the plot_example.ps file is actually correct, for its 
intended use.

It is worth pointing out that other solutions exist for this sort of 
thing, including the cmsyase font (see 
http://www.stat.auckland.ac.nz/~paul/R/CM/CMR.html) and the 'tikzDevice' 
package, so depending on what you are trying to do it might be worth 
taking a look at those.

Hope that helps.


pilchat wrote:
> Hi guys,
> to make it easier, here is a simple case with the same issues. I use the 
> short function below to make the attached PS file.
> Things to fix:
> -) the greek letter "lambda" is not printed, while "mu" is printed (see 
> the plot command)
> -) the annotation inside the plot area: the "+-" symbol and "(K)" 
> overlap with the substitute for tmed and tstd respectively (see the text 
> command). Also, how can I set the number of decimal digits for tmed and 
> tstd? (option(digits=4) does not work )
> Moreover, I'd like to make the characters thicker. Is there any way? 
> Finally, once I close the R session without saving it (I answer "n" when 
> quitting), the content of the ps file is erased. Do I miss something in 
> writing the function?
> Thanks
> Gaetano
> plot_example=function()
> {
> setPS()
> postscript (file='plot_example.ps',width=5,height=5,horizontal = FALSE, 
> paper = "special",family = "ComputerModern",encoding="TeXtext.enc")
> tmed<-1.23456789
> tstd<-1.23456789
> plot(c(0,1),c(0,1),xlab=expression(paste(lambda,mu,T)),main="",sub="(a)")#"lambda" 
> not printed
> text(.0,.8,substitute( T[disk,med] == tmed %+-% tstd 
> (K),list(tmed=tmed,tstd=tstd)),pos=4,cex=1.5  )#overlapping symbols and 
> numbers
> dev.off()
> }

Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz

More information about the R-help mailing list