简体   繁体   中英

Issue displaying PDF figures created with R on iOS devices

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, eg, 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?

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).

You could also try telling R not to use the Dingbats font to draw points: pdf(..., useDingbats = F)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM