5

I am trying to save plots which have female (\u2640) and male (\u2642) symbols. Here is an example to create a plot using this symbols (I am using RStudio):

gender <- rbinom(n=100, size=100, prob=0.5)
plot(gender, cex=2.5,
       pch=ifelse(gender %% 2 == 0, -0x2642L, -0x2640L),
       col=ifelse(gender %% 2 == 0, 2, 3), main="\u2640 and \u2642 Symbols")

It works and generates a plot with those symbols Plot. I can save it as picture (PNG) but when I try to save it as pdf all the symbols don't show up Plot.

Here is how I try to save it as pdf:

pdf("plot.pdf")
gender <- rbinom(n=100, size=100, prob=0.5)
plot(gender, cex=2.5,
       pch=ifelse(gender %% 2 == 0, -0x2642L, -0x2640L),
       col=ifelse(gender %% 2 == 0, 2, 3), main="\u2640 and \u2642 Symbols")

dev.off() 

I saw another post about similar problem here and it was suggested to use the CairoPDF. It did not work. I tried other family settings but it did not work either. Is there any other work around to save it as pdf with those symbols or the only way it is to save it as a picture. I would prefer to save it as pdf.

After a lot of tentatives I switched to command line and use quartz. After plotting the graph I use:

quartz.save(type = 'pdf', file = 'output.pdf')

It works perfectly. Why does it not works using the first code pdf("plot.pdf") but works with quartz.save(type = 'pdf', file = 'output.pdf')? Is it something with my system?

Thank you.

degopwn
  • 507
  • 1
  • 5
  • 14
  • What OS are you on? (or better, post the output of `sessionInfo()`) – Thomas Jul 29 '14 at 22:17
  • > sessionInfo() R version 3.1.0 (2014-04-10) Platform: x86_64-apple-darwin13.1.0 (64-bit) locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.1.0 – degopwn Jul 29 '14 at 22:20
  • possible duplicate of [using Unicode 'dingbat-like' glyphs in R graphics, across devices & platforms, especially PDF](http://stackoverflow.com/questions/5886018/using-unicode-dingbat-like-glyphs-in-r-graphics-across-devices-platforms-e) – Thomas Jul 29 '14 at 22:22
  • Switching `pdf` to `cairo_pdf` with everything else unchanged should work for you. – Thomas Jul 29 '14 at 22:22

1 Answers1

2

On my Mac this gives a pdf with astrological symbols. (Cobbled together from a search of similar questions on SO.) I didn't make the extra effort to "wrap" the full set neatly so the "printing of the later ones doesn't show up, but you can see Mars and Venus.

cairo_pdf("Venus_Mars.pdf",family="ArialUnicodeMS")
plot(1,1)
TestUnicode <- function(start="263c", end="2653", ...)
  {
    nstart <- as.hexmode(start)
    nend <- as.hexmode(end)
    r <- nstart:nend
    s <- ceiling(sqrt(length(r)))
    for(i in seq(r)) {
      try(points(.6+(i/10), .8 , pch=-1*r[i],...))
    }
  }
 TestUnicode()
dev.off()
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • 1
    Thanks. It works using Cairo. I was getting warning messages mainly these two: Cairo: "Fontconfig error: Cannot load default config file" and "Fontconfig warning: ignoring en_US_POSIX.UTF-8: not a valid region tag". Then I found a post in a google group about similar problem. It was suggested that a patched version of R from http://r.research.att.com/ would fix the problem. It did indeed. – degopwn Jul 30 '14 at 16:00
  • It's considered good form to upvote helpful answers. If you want to post your own information in another answer and checkmark as the best anser, that is also good form. – IRTFM Jul 30 '14 at 16:30
  • I actually tried to upvote your answer. I just need 2 more reputation to do that :P – degopwn Jul 30 '14 at 16:44
  • Oh. Color me redfaced. Thanks for letting me know. I didn't realize that. – IRTFM Jul 30 '14 at 17:00