====== Unicode in R graphics ======
===== The first solution =====
Simona and Kristijan have (September 2012) a problem with writing characters čšž in R graphics.
After some searching on the web (see [[#urls]]) I found the following solution
Sys.setlocale(category="LC_CTYPE", locale="slovenian")
setwd("D:/work/R/test")
x <- 1:10; y <- x**2
pdf.options(encoding = "CP1250")
pdf(file="csz0.pdf")
plot(x,y,xlab="\U0161irina",ylab="višina")
text(1,95,"\u010C \u0160\u017D")
text(1,90,"\u010D \u0161\u017E")
text(1,85,"Č ŠŽ")
text(1,80,"č šž")
dev.off()
The problem with this solution is that the characters Č and č are overlapping with
the other text. The "solution" is to insert an additional space.
{{:notes:pics:csz0.pdf}}
===== Unicode and SVG =====
The right solution would be the use of Unicode, but it seems that in R in PDF and Postscript it is not fully supported. There is a way around - R supports also the vector graphics in SVG.
setwd("C:/Users/Batagelj/test/R/svg")
x <- 1:10; y <- x**2
svg("csz.svg")
plot(x,y,xlab="\U0161irina",ylab="višina")
text(1,95,"\u010C\u0160\u017D",pos=4)
text(1,90,"\u010D\u0161\u017E",pos=4)
text(1,85,"ČŠŽ",pos=4)
text(1,80,"čšž",pos=4)
text(1,75,"\u0409\u0443\u0431\u0459\u0430\u043D\u0430",pos=4)
text(1,70,"\u00A9\u03B1\u222B\u263A\u20AC\u2640\u2642",pos=4)
dev.off()
It works!
{{:notes:pics:csz.svg}}
To get the picture in PDF we open it in [[http://inkscape.org/|Inkscape]] and save it in PDF.
{{:notes:pics:csz.pdf}}
There is also a direct way to use Unicode in PDF based on the library ''[[http://www.inside-r.org/r-doc/grDevices/cairo|Cairo]]''. You can check whether ''Cairo'' is supported in your version of R using the command ''capabilities()'' .
> capabilities()
jpeg png tiff tcltk X11 aqua http/ftp sockets libxml
TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE
fifo cledit iconv NLS profmem cairo
FALSE TRUE TRUE TRUE TRUE TRUE
The R on Windows supports it. So I tried:
library(cairoDevice)
Cairo_pdf("csz1.pdf",width=7,height=7,pointsize=10)
plot(x,y,xlab="\U0161irina",ylab="višina")
text(1,95,"\u010C\u0160\u017D",pos=4)
text(1,90,"\u010D\u0161\u017E",pos=4)
text(1,85,"ČŠŽ",pos=4)
text(1,80,"čšž",pos=4)
text(1,75,"\u0409\u0443\u0431\u0459\u0430\u043D\u0430",pos=4)
text(1,70,"\u00A9\u03B1\u222B\u263A\u20AC\u2640\u2642",pos=4)
dev.off()
We get
{{:notes:pics:csz1.pdf}}
It (almost) works! It seems that in the Unicode font used by Cairo some characters do not have a description.
If we replace the command ''Cairo_pdf'' with
> Cairo(width=7,height=7,pointsize=10)
and delay the command ''dev.off()'' we can get the picture also on the screen.
===== URLs =====
* Paul Murrell and Brian Ripley: [[http://cran.r-project.org/doc/Rnews/Rnews_2006-2.pdf|Non-Standard Fonts in PostScript and PDF Graphics]], R-news, p. 41-46.
* [[http://blog.revolutionanalytics.com/2011/11/r-214-for-windows-now-with-svg-support.html|R 2.14 for Windows: now with SVG support]]: One additional new feature in the latest release of R: the standard binaries of R 2.14 from the R Project now include Cairo support. For Windows users, this means that you can now create SVG graphics in R -- the best format for displaying R graphics on the web -- without having to compile R yourself. [[http://blog.revolutionanalytics.com/2011/07/r-svg-graphics.html|High-quality R graphics on the Web with SVG]].
* [[http://blog.revolutionanalytics.com/2009/01/10-tips-for-making-your-r-graphics-look-their-best.html|10 tips for making your R graphics look their best]]
* [[http://www.omegahat.org/SVGAnnotation/|The SVGAnnotation Package]]: make the plots interactive and dynamic in simple ways such as: add tooltips, add hyperlinks, animate the plots, implement simple linking, add CSS information to an SVG document, and generally use SVG's rich facilities. [[http://www.jstatsoft.org/v46/i01/paper|Paper]]
NEUREJENO
* http://stackoverflow.com/questions/12075555/non-standard-fonts-in-postscript-and-pdf-graphics-with-r-how-to-reproduce-examp
* http://stackoverflow.com/questions/5886018/using-unicode-dingbat-like-glyphs-in-r-graphics-across-devices-platforms-e
* http://stackoverflow.com/questions/5031630/how-to-source-r-file-saved-using-utf-8-encoding
* http://stats.stackexchange.com/questions/21380/in-r-what-is-the-best-graphics-driver-for-using-the-graphs-in-microsoft-word
* http://stat.ethz.ch/R-manual/R-patched/library/grDevices/html/plotmath.html
* http://rwiki.sciviews.org/doku.php?id=tips:graphics-misc:symbols
* http://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html
* http://www.stat.auckland.ac.nz/~paul/gridSVG/gridsvg.pdf
* http://www.stat.auckland.ac.nz/~paul/Talks/gridSVG/slide8.html
* http://www.stat.auckland.ac.nz/~paul/R/grImport/import.pdf
* http://www.inside-r.org/r-doc/grDevices/postscript
* http://paperpools.blogspot.com/2007/09/zoonekynd-on-murrell-on-r-graphics.html
* https://r-forge.r-project.org/projects/gridsvg/
* https://r-forge.r-project.org/projects/svgmapping/
* http://code.google.com/p/google-motion-charts-with-r/
* http://bmb-common.blogspot.com/2011/05/unicode-symbols-in-r.html
* http://developer.r-project.org/TechDocs/
* http://markmail.org/message/kzjts7zbxmluhuqy
* http://mikelove.wordpress.com/2009/01/25/svg-in-r/
* http://cran.r-project.org/web/packages/Cairo/index.html
* http://www.r-bloggers.com/creating-svg-graphics-for-web-publishing/
* http://rgraphics.limnology.wisc.edu/routput.php
* http://en.wikibooks.org/wiki/Statistical_Analysis:_an_Introduction_using_R/Contributors/uploadToCommons.r
* http://www.ceb-institute.org/bbs/ ggplot2
* http://en.wikibooks.org/wiki/LaTeX/Importing_Graphics