Cla*_*lke 10
我一直致力于通过在 ggplot 中启用降价样式的 ggtext 包来寻找一种更简单、更灵活的方法来实现这一目标。目前正在开发中,但很快就会发布到 CRAN(2020 年初)。
library(ggplot2) # may require: remotes::install_github("tidyverse/ggplot2")
library(ggtext) # remotes::install_github("clauswilke/ggtext")
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", "*Manual*")
) +
theme(legend.text = element_markdown())
Run Code Online (Sandbox Code Playgroud)

由reprex 包(v0.3.0)于 2020 年 1 月 1 日创建
您可以使用expression和italic在标签上创建斜体文本。
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
Run Code Online (Sandbox Code Playgroud)