Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue displaying PDF figures created with R on iOS devices

Tags:

r

ios

pdf

ggplot2

I'm making some plots in R. The resulting PDFs don't display properly on iOS devices like the iPhone. For example, here's a stock ggplot2 figure created as a PDF:

library(ggplot2)
mpg.eg <- within(mpg[1:74,], {
  model <- reorder(model, cty)
  manufacturer <- reorder(manufacturer, -cty)
})

pdf(file="figures/ios-example.pdf")
p <- qplot(cty, model, data=mpg.eg)
p + facet_grid(manufacturer ~ ., scales="free", space="free") +
  opts(strip.text.y = theme_text())
dev.off()

When viewed on an iPhone, the dots in the dotplot are not displayed. See, e.g., the resulting pdf if you're on an iOS device.

I understand from reading the docs that this is most likely a problem with limited font availability and the vagaries of PDF rendering on iOS, not an issue with pdf creation in R. I had thought that maybe embedding fonts in the PDF with

embedFonts("figures/ios-example.pdf")

would sort things out, but it doesn't. Is there something I can do to work around this iOS issue beyond just making the figure available in some other format?

like image 232
Kieran Avatar asked Feb 05 '11 19:02

Kieran


1 Answers

embedFonts by default doesn't embed the standard PDF font set, and therefore doesn't actually make any significant changes to your example PDF. Try instead

embedFonts("figures/ios-example.pdf",
           options="-dSubsetFonts=true -dEmbedAllFonts=true")

and if that doesn't work, tack "-dPDFSETTINGS=/printer" on there too.

[EDIT August 2020: With current versions of R, another thing to try is switching from the pdf device to the cairo_pdf device. cairo_pdf uses a more sophisticated library for PDF generation and, among other things, it embeds fonts itself.]

For what it's worth, though, your example is displayed correctly on the only iOS device I have to hand (iPad, OS version 4.2.1).

like image 192
zwol Avatar answered Sep 22 '22 21:09

zwol