How to italicize one category in a legend in ggplot2

前端 未结 2 566
不知归路
不知归路 2020-12-11 19:01

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

As an example, consider the following plot. How can I set \"Manu

2条回答
  •  旧时难觅i
    2020-12-11 19:06

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

    library(ggplot2)
    
    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")))
      )
    

    Created on 2020-01-01 by the reprex package (v0.3.0)

提交回复
热议问题