[R] display UTF8 characters in pdf
Olivier CROUZET
Olivier.Crouzet at univ-nantes.fr
Fri Mar 10 21:22:02 CET 2017
Hi,
AFAICT, you need to use a Cairo device for being able to display some
Unicode
characters in a plot.
From my experience, the CairoPDF() from library(Cairo) does not work
(and I don't understand the difference with cairo_pdf()), but the
cairo_pdf() from grDevices does work perfectly well for this aim. As far
as I'm concerned, I use it with both ggplot2 and regular plots and it
does a perfect job. Here is a short example:
In an R console:
cairo_pdf(filename = "test.pdf")
plot(1,1,pch = "\u254")
dev.off()
Also, I use it with knitr and it works great. You just have to declare a
specific device ("cairo_pdf").
For example, in an RMarkdown document:
```{r ipaunicode, echo=TRUE, dev='cairo_pdf'}
plot(1, 1, pch = "\u254")
```
and in a LaTeX / knitr document as well:
<<ipaunicode, dev="cairo_pdf">>=
plot(1, 1, pch = "\u251")
@
Hope this helps.
Yours.
Olivier.
On Fri, 10 Mar
2017 17:06:25 +0100 Thierry Onkelinx <thierry.onkelinx at inbo.be> wrote:
> Dear all,
>
> I'd like to use some UTF-8 characters in a plot. Some of them are not
> rendered with saving the plot as pdf. Any suggestions?
>
> library(ggplot2)
> symbols <- c("\U1F697", "\U00A9", "\U24DA", "\U00C1")
> test <- data.frame(
> x = seq_along(symbols) %% ceiling(sqrt(length(symbols))),
> y = ceiling(seq_along(symbols) / ceiling(sqrt(length(symbols)))),
> symbol = symbols
> )
> p <- ggplot(test, aes(x = x, y = y, label = symbol)) + geom_text(size
> = 10) p
> ggsave(p, file = "test.png")
> ggsave(p, file = "test.pdf")
>
> The last command gives several similar warnings, all related to the
> symbols which are not rendered properly:
>
> Warning messages:
> 1: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), ... :
> conversion failure on '' in 'mbcsToSbcs': dot substituted for <f0>
>
> I'm running R 3.3.2 under Ubuntu 16.04.1 and ggplot2 2.2.1
>
> Best regards,
>
> Thierry
>
>
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for
> Nature and Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
>
> To call in the statistician after the experiment is done may be no
> more than asking him to perform a post-mortem examination: he may be
> able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does
> not ensure that a reasonable answer can be extracted from a given
> body of data. ~ John Tukey
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.
--
Olivier Crouzet, PhD
/Assistant Professor/
@LLING - Laboratoire de Linguistique de Nantes
UMR6310 CNRS / Université de Nantes
/Guest Researcher/
@UMCG (University Medical Center Groningen)
ENT department
Reijksuniversiteit Groningen
More information about the R-help
mailing list