[R] pdf: plotting very small points

Rebecca.Hiller at meteoswiss.ch Rebecca.Hiller at meteoswiss.ch
Fri Mar 7 16:36:35 CET 2014



> -----Original Message-----
> From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
> Sent: Freitag, 7. März 2014 16:00
> To: Duncan Murdoch; Hiller Rebecca; r-help at r-project.org
> Subject: Re: [R] pdf: plotting very small points
> 
> On 05/03/2014 17:24, Duncan Murdoch wrote:
> > On 05/03/2014 8:34 AM, Rebecca.Hiller at meteoswiss.ch wrote:
> >> Dear all,
> >>
> >> Ghostscript (version 9.05) cannot open pdfs produced with R (version
> >> 3.0.2) that contain very small points in plots. Other pdf readers
> >> (evince, AcrobatReader) are able to open the file. If setting cex=0,
> >> the pdf is readable again:
> >>
> >> # does open with gs
> >> pdf("cex_small.pdf")
> >> plot(1,1,cex=10^-3)
> >> dev.off()
> >>
> >> # does not open with gs
> >> pdf("cex_verysmall.pdf")
> >> plot(1,1,cex=10^-4)
> >> dev.off()
> >>
> >> # does open with gs
> >> pdf("cex_zero.pdf")
> >> plot(1,1,cex=0)
> >> dev.off()
> >>
> >> For sure, I can check the value assigned to cex before plotting.
> >> However, this is rather inconvenient. I need to convert the graphs
> >> using convert to other file formats, hence simply using another pdf
> >> readers is not an option either. Any suggestions?
> >
> >  From your description, it sounds like a Ghostscript bug, so you might
> > want to report it to them.  But a simple workaround is to just round
> > your cex values, e.g. use round(cex, 2) and 0.001 will become 0.
> 
> Or a different interpretation of the PDF standard.
> 
> Why anyone would want an object of size less than 0.01 bp (which is where
> the issue arises) escapes me.
> 
> I'll probably do the rounding internally for safety.

Thank you very much for your suggestions. Setting the argument useDingbats=FALSE in the pdf call does solve the problem. 
I agree that plotting such small points is pointless, but point size varies depending on other variables. Since I use this approach in many scripts, I was curious if there is a simpler approach than adding round in all calls of the method points or overwriting the method and rounding cex before calling graphic::points.

# does open with gs
pdf("cex_verysmall.pdf",useDingbats=FALSE)
plot(1,1,cex=10^-4)
dev.off()

Cheers,
Rebecca Hiller


> 
> 
> >
> > Duncan Murdoch
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> 
> --
> 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




More information about the R-help mailing list