Any way to disable the "minus hack" in PDF/Poscript output?
ggplot2, graphics, r
Solution
If your machine supports it (and you can type `capabilities()` to learn whether it does), you could instead use `cairo_pdf()`. It seems to handle `"-"` more like the other plotting devices:
Here, because I might as well include it, is the code I used for the two pdfs above:
cairo_pdf("cairo_pdf.pdf", width=6, height=3.5)
par(mar=c(10,4,4,1))
plot(1:10, type = "n", axes = FALSE,
main = "Plotted using cairo_pdf()",
ylab = "", xlab = "x-y", cex.lab = 10)
dev.off()
pdf("pdf.pdf", width=6, height=3.5)
par(mar=c(10,4,4,1))
plot(1:10, type = "n", axes = FALSE,
main = "Plotted using pdf()",
ylab = "", xlab = "x-y", cex.lab = 10)
dev.off()
Problem
In R, when saving a plot to a PDF or Postscript file, hyphens in axis labels get turned into minus signs. This, apparently, is by design. According to the documentation for the "postscript" device: There is an exception [to the normal encoding rules]. Character 45 (‘"-"’) is always set as minus (its value in Adobe ISOLatin1) even though it is hyphen in the other encodings. Hyphen is available as character 173 (octal 0255) in all the Latin encodings, Cyrillic and Greek. (This can be entered as ‘"\uad"’ in a UTF-8 locale.) Is there any way to turn this feature off? The problem I'm having is that I often save plots in various formats and, if I follow the suggested "\uad" workaround, I get the expected hyphens in Postscript/PDF output but nothing when rendering my plots to other graphics devices like PNG. I'd rather not have to create two versions of each plot, one for PDF and one for PNG. If I could disable the "minus hack", the rendering behavior across graphics devices would be consistent, and I could simply "print" a plot to multiple devices to get it in different formats. For example, I'd like to be able to do the following, and have the hyphens render consistently in both PDF and PNG versions of the plot: ``` p <- qplot(arrival_rate, mean_service_time, data = response_times, ...) ggsave(p, file = "/tmp/service-scaling.pdf", useDingbats = F) ggsave(p, file = "/tmp/service-scaling.png") ``` Thanks for your help!