I am trying to save plots with legends containing UTF characters for Males and Females to pdf in R
. When I plot to graphics device :
plot(1)
legend('topright', bty = 'n',
expression(italic("legend"~"\u2640"~"\u2642")))
the legend of plot looks as expected
I can even save it to pdf by right click and "save to pdf". However, when I use inbuilt function pdf
pdf('test.pdf')
plot(1)
legend('topright', bty = 'n',
expression(italic("legend"~"\u2640"~"\u2642")))
dev.off()
it drops a warning and shows corrupted characters instead:
cairo_pdf
does not drop a warning, but it does not show the correct symbols either:
According to this post, I should specify encoding that would support my symbols, however I have no idea how to find out which it does (besides default Helvetica
I tried MacRoman
without success).
It is apparent that it is possible for R to generate pdf that contains these symbols (because I am able to do so by the right click). However, I would like to achieve that in automatized manner.
My R session settings:
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.5 (El Capitan)
locale:
[1] en_US.UTF-8/C/en_US.UTF-8/C/en_US.UTF-8/C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
I also managed to reproduce same behaviour on another computer with macOS Sierra 10.12.1.