【问题标题】:Using subscript and italics in ggplot2 axis labels在 ggplot2 轴标签中使用下标和斜体
【发布时间】:2021-07-23 00:07:05
【问题描述】:

我正在使用 ggplot2 创建直方图,但一直在努力格式化轴标签。到目前为止,我习惯于在下面的代码中在标签中插入一个希腊字母,但也希望“K”为斜体,“D”为下标,以便标签看起来像 K D (µM)

labs(x=expression(paste('KD (', mu, 'M)')))

【问题讨论】:

标签: r ggplot2 graph histogram axis-labels


【解决方案1】:

不使用expression 方法的最简单的格式化方法是使用简单的html。 我推荐ggtext package

另见this answerggplot2中的希腊文本

library(tidyverse)
library(ggtext) # 
mtcars %>% 
  ggplot() +
  geom_histogram(aes(drat), bins = 20) +
  labs(x="K<sub><i>D</i></sub>(\u00b5M)") +
  theme(axis.title.x = element_markdown())

reprex package (v2.0.0) 于 2021-04-29 创建

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-25
    • 2015-02-11
    • 2019-01-26
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多