Any way to disable the "minus hack" in PDF/Poscript output?
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()
There is a workaround for pdf() described here:
replace the "-" hyphen with the unicode character "\255"
or in UTF8 "\uad"
.
This might not print nicely in the R-console, but will in the pdf.
It can easily be substituted using gsub("-", "\uad", "x-y")
:
pdf("pdf.pdf", width=5, height=4)
par(mar=c(6,2,2,2), mfrow=c(2,1))
plot(1:10, type = "n", axes = FALSE,
main = "Default",
ylab = "", xlab = "x-y", cex.lab = 8)
plot(1:10, type = "n", axes = FALSE,
main = "with '\\uad'",
ylab = "", xlab = gsub("-", "\uad", "x-y"), cex.lab = 8)
dev.off()
I ended using this solution because I want to export a pdf in CMYK colormode, which is not possible in cairo_pdf (and the alternative of later conversion to CMYK makes the filesize increase by 10-fold for small files). I hope somebody else can use it.
[Edit]: added a missing " (and this to avoid the 6 character limit)