Saving plot using Hebrew encoding (or UTF-8) for text in pdf / svg devices in R?

I would like to keep a graph in which text (for example, in the title) is used in Hebrew. Attempting to do the following will not:

pdf("temp.pdf")
plot(1, main = "שלום")
dev.off()

svg("temp.svg")
plot(1, main = "שלום")
dev.off()

Although use:

png("temp.png")
plot(1, main = "שלום")
dev.off()

Gives the correct result.

Is there any way to fix it for pdf and svg?

Thank.

+5
source share
2 answers

Try using Cairo:

library(Cairo)
CairoPDF("temp.pdf")
plot(1, main = "שלום")
dev.off()

CairoSVG("temp.svg")
plot(1, main = "שלום")
dev.off()
+2
source

You need to use pdfFontsto assign a font with the corresponding glyphs. At the moment, such a font appears on the device screen, but your pdfFonts have a drawback when it comes to Hebrew.

?pdfFonts
names(pdfFonts()
+1
source

All Articles