简体   繁体   中英

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

I would like to save a plot where the text (for example, in the title) is using Hebrew. Trying the following won't work:

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

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

Although using:

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

Will give the correct output.

Is there a way to fix it for pdf and svg as well?

Thanks.

Try using Cairo :

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

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

You need to use pdfFonts to assign a font that has the proper glyphs. At the moment you screen device appears to be using such a font but your pdfFonts are deficinet when it comes to Hebrew.

?pdfFonts
names(pdfFonts()

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