Reputation: 3568
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...
...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.
Upvotes: 8
Views: 2059
Reputation: 46
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")
Upvotes: 3