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]]
install.packages("emojifont") library(emojifont) ... # plot as before. Best, Ista On Fri, Mar 10, 2017 at 11:06 AM, 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.
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
Hi This does not help with a solution, but ... The standard PDF device only does single-byte character sets (sbcs in the warning message). The conversion from a multi-byte character set (mbcs), which is what UTF8 is, will only work if the characters map to a single-byte character set (things like ASCII, Latin1, etc). The A-acute, probably the copyright sign, and maybe even the k-in-a-circle might survive the conversion, but a little drawing of a car does not. Paul On 11/03/2017 5:06 a.m., Thierry Onkelinx 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. >-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
Dear all, Thanks to Ista and Olivier. The solution of Ista works for some characters but not all. The solution of Olivier works, at least for the characters that I've tried. Best regards, 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 2017-03-10 21:22 GMT+01:00 Olivier CROUZET <Olivier.Crouzet at univ-nantes.fr>:> 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 > > > ______________________________________________ > 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/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]