【问题标题】:Two-line annotations using plotmath expressions in ggplot在 ggplot 中使用 plotmath 表达式的两行注释
【发布时间】:2021-02-20 06:57:23
【问题描述】:

我想将ggplot中注释的第二行中的单个字符斜体

剧情是这样的

iris %>%
  ggplot(aes(x = Sepal.Length,
             y = Species,
             fill = Species)) +
         stat_summary(geom = "bar", fun = "mean") +
         theme(legend.position = "none") -> p

现在我可以像这样对情节进行注释,并让单个字符斜体,而其余字符则为单斜体。

p + annotate("text", 
             label = "italic(N)==74",
             x = 3,
             y = 2,
             parse = T)  

现在说我想要一个粘贴了某些字符的两行注释。我可以这样做使用 plotmath

p + annotate("text", 
             label = paste("AUC = ", 
                           round(60.1876,3),
                           "\nN = ",
                           74,
                           sep = ""),
             x = 3,
             y = 2,
             size = 4)

如您所见,N 字符是单体的。有没有办法让它看起来像第二张图,但 N 斜体,无论是使用 plotmath 还是其他一些技术?

【问题讨论】:

    标签: r ggplot2 plotmath


    【解决方案1】:

    使用atop 在文本之上绘制文本。见?plotmath

    p +
      annotate(
        "text", 
        label = paste0("atop(AUC == ", round(60.1876, 3), ",italic(N) == 74)"),
        x = 3,
        y = 2,
        size = 4,
        parse = TRUE
      )
    

    【讨论】:

      猜你喜欢
      • 2018-05-24
      • 2018-05-13
      • 2021-05-06
      • 2013-01-08
      • 2018-11-13
      • 1970-01-01
      • 2014-12-08
      • 1970-01-01
      • 2020-03-23
      相关资源
      最近更新 更多