0

Let say I have below histogram-

set.seed(1)
df <- data.frame(Type=c(rep("A",1000),rep("B",4000)),
                 Value=c(rnorm(1000,mean=25,sd=10),rchisq(4000,15)))
# you start here...
library(ggplot2)
ggplot(df, aes(x=Value))+
  geom_histogram(aes(y=..density..,fill=Type),color="grey80")+
  facet_grid(Type~.)

Now, I want to rename the facet_grid i.e. instead of A and B, I want to place \sigma_1 and \sigma_2 in actual greek alphabet (1 & 2 being suffix)

Is there any way to achieve this?

Any pointer will be highly helpful

Bogaso
  • 2,838
  • 3
  • 24
  • 54

1 Answers1

1

You can use plotmath expressions in combination with label_parsed() as the facet's labeller argument.

set.seed(1)
df <- data.frame(Type=c(rep("A",1000),rep("B",4000)),
                 Value=c(rnorm(1000,mean=25,sd=10),rchisq(4000,15)))
library(ggplot2)

df$label <- ifelse(df$Type == "A", "sigma~1", "sigma~2")

ggplot(df, aes(x=Value))+
  geom_histogram(aes(y=..density..,fill=Type),color="grey80")+
  facet_grid(label~., labeller = label_parsed)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

duckmayr
  • 16,303
  • 3
  • 35
  • 53
teunbrand
  • 33,645
  • 4
  • 37
  • 63