How to italicize 1 category in a legend in ggplot2

北城余情 提交于 2019-12-12 20:06:43

问题


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

Thanks!


回答1:


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



来源:https://stackoverflow.com/questions/48688404/how-to-italicize-1-category-in-a-legend-in-ggplot2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!