How to italicize boxplot label in R using ggplot2?

Like every other tool for statistical analysis R does not display the labels of a boxplot in italics, thus if we want to do this, we need to do it manually. In ggplot2, we have a function scale_x_discrete that can be used to change the default font to italic using expression function.

Example

ggplot(df,aes(x,y))+geom_boxplot()+scale_x_discrete(labels=expression(italic(Female),italic(Male)))

Output

Updated on: 2026-03-11T23:22:53+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements