SamPassmore
SamPassmore

Reputation: 1365

Special characters not appearing in PDF

I am creating a plot that plots text, some of which contains special characters. When I make this plot within RStudio it seems fine, and when I export to JPEG it is fine. However, when I export to PDF some characters are not printed correctly. Is there a way to encode the file appropriately so the correct characters are displayed?

here is a small example to show the issue:

This is fine:

plot(1, 1, type = "n")
text(1, 1, "bʱaːu")

This is not fine:

pdf('test.pdf')
plot(1, 1, type = "n")
text(1, 1, "bʱaːu")
dev.off()

Upvotes: 6

Views: 3663

Answers (1)

jay.sf
jay.sf

Reputation: 72583

Use grDevices::cairo_pdf instead.

grDevices::cairo_pdf("example.pdf")
plot(1, 1, type = "n")
text(1, 1, "bʱaːu")
dev.off()

Result

enter image description here

BTW, text(1, 1, paste0("b", sprintf("\U02B1"), "aːu")) would give you an unicode representation of ʱ.

Upvotes: 6

Related Questions