How to italicize 1 category in a legend in ggplot2

2019-08-07 01:37发布

For my legend in ggplot2 I have 2 categories, how do I italicize only 1 category and not the other?

Thanks!

1条回答
时光不老,我们不散
2楼-- · 2019-08-07 02:20

You can use expression and italic to create italicised text on labels.

data("mtcars")
library(ggplot2)

p <- ggplot(data = mtcars, aes(x = as.factor(am), fill = as.factor(am))) + 
  geom_bar() + 
  scale_fill_discrete("Transmission", breaks = c(0, 1),
                       labels = c("Automatic", expression(italic("Manual"))))
p

enter image description here

查看更多
登录 后发表回答