0

I think this might be related to an update to ggplot2, but could also be something on my system. Trying to track down the cause. I get hollow rectangles when using the pdf() output device, and [expected] solid circles when using png().

This is on arch linux; should I be looking for an change in ggplot2, something new in R in general, or some backend on my system that's used to generate these outputs? I don't know what's all involved but it's new behavior to me.

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_2.1.0

loaded via a namespace (and not attached):
[1] labeling_0.3     colorspace_1.2-6 scales_0.4.0     plyr_1.8.4      
[5] gtable_0.2.0     Rcpp_0.12.6      grid_3.3.1       munsell_0.4.3 

Some test code:

library(ggplot2)
dat <- data.frame(x = 1:10, y = (1:10)^2)
p <- ggplot(dat, aes(x = x, y = y)) + geom_point()

Comparison screenshots

Output on R graphics device:

p

enter image description here

Output to png() device:

png("./test.png", width = 1600, height = 900, res = 150)
p
dev.off()

enter image description here

Output to pdf() device (viewed with evince, though gimp shows the same):

pdf("./test.pdf", width = 9, height = 6)
p
dev.off()

Hunting

I did look around a bit and didn't find any obvious hits for "ggplot2 using squares instead of circles pdf" or similar on google.

I also perused the version 2 changelog and searched the page for "point" and "shape". I see a reference to a switch from pch 19 instead of 16, but both of those are solid circles.

Looking at various google image hits for incantations of "ggplot2 geom_point pdf", "ggplot2 geom_point hollow" and similar didn't show anything obvious (unless the user appeared to be trying to get hollow shapes and specifying non-default pch values via shape).

enter image description here

Hendy
  • 10,182
  • 15
  • 65
  • 71
  • 1
    It's a font issue - the points are actually characters in a font that is not part of your PDF. If you run `grDevices::embedFonts` on the PDF file after saving it that should fix it. – Gregor Thomas Sep 26 '16 at 16:12
  • 1
    Some related questions: [ggplot embedded fonts in pdf](http://stackoverflow.com/q/27542302/903061) suggests that using `device = cairo_pdf` as a `ggsave` argument helps, and [ggplot2 pdf import in Adobe Illustrator missing font AdobePiStd](http://stackoverflow.com/q/9992275/903061) suggests setting `useDingbats=FALSE`. – Gregor Thomas Sep 26 '16 at 16:18
  • Awesome. This supremely helpful. The above requires running something every time... does the fact that it's a "font that is not part of my pdf" mean I'm missing a font that would render as expected, or that others would see these as circles if opened on their system? – Hendy Sep 26 '16 at 18:17
  • Fonts can be embedded in PDF documents so that they render the same even if someone opens it on a computer without the font installed on it. I've never been clear on why a font you clearly have (R is using it!) doesn't seem to be available when you open the PDF. That said, if you embed the font, it *should* look the same on any computer using any PDF viewer, regardless of whether the font is installed. – Gregor Thomas Sep 26 '16 at 18:23
  • Thanks for the clarification. I'm going to look into a general setting I could put in `.Renviron` or `.Rprofile`. That would be awesome and avoid me forgetting to do this... – Hendy Sep 26 '16 at 18:26
  • Not as easy as I expected. I don't seem to have dingbats, so the properties of the PDF say that `ZapfDingBats` is expected and that `Droid Sans` was substituted. Arch has a bunch of MS and adobe font packages claiming to contain dingbats, but the behavior is the same and I don't see any `.ttf` or `.otf` files looking like dingbats after they're installed. `embedFonts("./file.pdf")` doesn't change anything for me. I also tried `cairo_pdf` and I get circles, but the axis text looks horrible. – Hendy Sep 26 '16 at 20:23
  • `useDingbats=F` works. The document is only using `Helvetica` now (subbed by `NimbusSans` on my system). If you wanted to write these up as an answer, I'd accept it. Otherwise, perhaps it should be marked as a duplicate pointing to the other posts? – Hendy Sep 26 '16 at 20:25
  • 1
    Since your end solution is the same, I think marking as a dupe makes the most sense. – Gregor Thomas Sep 26 '16 at 21:00

0 Answers0