Unicode characters not showing when exporting to pdf in R

662 views Asked by At

I am trying to export some unicode characters in the U+1xxxx format from R to pdf using ggplot2 (this is one example: https://unicode-table.com/en/1F321/). In R, the output is great when I have it in the ggtitle as ggtitle("Temperature range \U1F321"):

enter image description here

However, when I export the plot to pdf it appears as these blocks below:

enter image description here

I have tried many things that other people suggested (such as using cairo pdf and the showtext package) but none of it worked. I am using Windows.

Thank you very much!

EDIT: I'm saving as pdf using pdf("example.pdf") or cairo_pdf("example.pdf")

Reproducible code:

ggplot(mtcars, aes(x=cyl, y=mpg)) + geom_point() + ggtitle("Temperature range \U1F321") 

cairo_pdf("plot_cairo.pdf")
ggplot(mtcars, aes(x=cyl, y=mpg)) + geom_point() + ggtitle("Temperature range \U1F321") 
dev.off()

pdf("plot_normal.pdf")
ggplot(mtcars, aes(x=cyl, y=mpg)) + geom_point() + ggtitle("Temperature range \U1F321") 
dev.off()

Also, just want to state my intentions more clearly. I'm just aiming to have a high-resolution ggplot exported from R to Word. When I export it as an image, the characters show well but the resolution is of poor quality. Following suggestions from other users, I'm therefore first exporting it as pdf and then importing it to Word as an object from the "Insert" tab:

enter image description here

Using this method, the plot is of much better resolution in Word, but the unicode characters don't show up well. So if maybe someone else has another suggestion on how to get a high quality ggplot exported from R to Word while still preserving the unicode characters, that would also work! Thank you!!

0

There are 0 answers