13 Jul

Italic label in a plot using facet_wrap

Hi!
I just got asked by a journal to italicize some labels in a plot… So here is a small code snippet to assist you when you get asked the same:

factor1=rep(letters[1:3], each=3)
factor2=rep(1:3,times=3)
x=rep(1,9)
y=1:9
df=cbind.data.frame(factor1,factor2,x,y)
 
levels(df$factor1)= c("a"=expression(paste("factor_", italic("a"))),
                      "b"=expression(paste("factor_", italic("b"))),
                      "c"=expression(paste("factor_", italic("c"))))
 
ggplot(df, aes(x=x, y=x))+facet_grid(factor2~factor1, labeller=label_parsed)+geom_point()

And the result is:
italic

Thanks to Berengere Husson for the tip!

Leave a Reply

Your email address will not be published. Required fields are marked *