I am trying to add Greek letters in legend of my GGPLOT
. Below is my approach
library(ggplot2)
set.seed(1)
Dat = rbind(data.frame(var1 = 'x1', var2 = rnorm(10000, 10, 3)),
data.frame(var1 = 'x2', var2 = rnorm(10000, 10, 3)))
Dat %>%
ggplot() +
geom_histogram(data = Dat, aes(x = var2, y = ..density.., fill = var1)) +
scale_colour_manual(labels = expression(paste('tau[', 1:2, ']', sep = '')))
With above approach, I am getting original variables in legend.
I also tried below (as explained in How to use Greek symbols in ggplot2?)
Dat %>%
ggplot() +
geom_histogram(data = Dat, aes(x = var2, y = ..density.., fill = var1)) +
scale_x_discrete(labels = c('x1' = expression(alpha),
'x2' = expression(beta)))
But still I failed to change the legend.
How can I modify those variables names to greek letters preserving all other properties of my plot?