8

I need to save a graph created in ggplot with greek symbols as facet labels.

Here is the code for the graph

library(bayesplot)
library(ggplot2)
df <- data.frame(var1 = rnorm(1e4, 0, 1),
                 var2 = rnorm(1e4, 6, 4),
                 var3 = rnorm(1e4, 10, 3))
names(df) <- c("\u03C3", "\u03B4", "\u03BC")
tp <- bayesplot::mcmc_trace(df)
tp

Now this prints to RStudio's plot window just fine...enter image description here

...with the greek symbols coming up nicely. It also saves nicely to image files. But if I try to save to eps or pdf...

ggplot2::ggsave(filename = "plotMu.eps", 
                plot = tp, 
                device = "eps", 
                dpi = 1200, 
                width = 15,
                height = 10, 
                units = "cm")

...these greek symbols come up as double dots ..

So how do I get these symbols to show up on the eps/pdf. I have tried saving with encoding and choosing ASCII but this strategy only works for plotmath expressions and expression() statements, which doesn't really help my situation as neither of these work for column headings.

I would really appreciate someone outlining step-by-step the process for getting this done. All the explanations online tend to assume some knowledge that I don't have.

5
  • What OS are you using? Possible related: stackoverflow.com/questions/28446737/…
    – MrFlick
    Commented Aug 19, 2019 at 14:27
  • 1
    Try changing the line device="pdf" to device=cairo_pdf and see if the problem is solved. That is one of the solutions in the @MrFlick possible related link.
    – deepseefan
    Commented Aug 19, 2019 at 14:35
  • Thank you @deepseefan. I got an error saying Error: Unknown graphics device 'cairo_pdf'. In any case I think I underplayed the importance of the .eps. That's actually the problem that most frustrates me because .eps files are the format journals want their figures in these days. I just included pdf because I was getting the same baffling .. symbols on both .pdf and .eps. I think I will alter the original post to reflect this.
    – llewmills
    Commented Aug 19, 2019 at 23:41
  • @llewmills, that's probably you don't have it on your system. Have a look here to install the one appropriate to your system. Down the line, it can as well save you from the trouble of embedding the fonts for camera ready.
    – deepseefan
    Commented Aug 20, 2019 at 11:59
  • Thank you so much @deepseefan. So helpful. I hope one day to solve the Greek-Character-EPS puzzle. It's eluded me for so long. For now I will just have to write 'Mean' and 'sd' in my facet headings instead of mu and sigma. Not the end of the world but the pedant in me will always be annoyed I couldn't solve it.
    – llewmills
    Commented Aug 20, 2019 at 14:32

1 Answer 1

3

I had the same problem and found that using device = cairo_ps fixed it! For example,

ggplot2::ggsave(filename = "plotMu.eps", 
plot = tp, 
device = cairo_ps, 
dpi = 1200, 
width = 15,
height = 10, 
units = "cm")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.