Saturday, June 23, 2018

Exporting graphics with Unicode in R using png() or Cairo(), on Windows

I am able to display Unicode characters on a plot within my R session, but when I try to export the figure using e.g. png(), CairoPNG(), cairo_pdf(), etc., some (although not all) of these fail to appear. For example, the following simple plot shows the correct characters for me in the R window:



plot( 1:9,
c(280, 540, 750, 1434, 1078, 728, 662, 606, 785),
pch=-as.hexmode(c("4E00", "4E8C", "4E09", "56DB", "4E94", "516D", "4E03", "516B", "4E5D")),
xlab="Digit",
ylab="pixels"

)


figure



However, when I use png() first to try to save this image to disk, the characters are replaced with boxes. The previous discussions on this I managed to find (e.g. here and here) suggested using cairo_pdf. But I get basically the same result with cairo_pdf(), CairoPNG(), cairo_ps(), etc. Changing the locale, as suggested here, also still got the same result.



figure



Some session info:




R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252


attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] yarrr_0.1 lme4_1.1-8 Matrix_1.2-2 boot_1.3-17 Cairo_1.5-9

loaded via a namespace (and not attached):
[1] minqa_1.2.4 MASS_7.3-43 tools_3.2.2 Rcpp_0.12.4 splines_3.2.2
[6] nlme_3.1-121 grid_3.2.2 nloptr_1.0.4 lattice_0.20-33



Any suggestions would be greatly appreciated!



EDIT: Fixed a mistake in the code I had posted, sorry about that; you should hopefully be able to replicate the plot now.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...