【问题标题】:Multiple lines of text/ label in mixed italic and regular fonts in ggplotggplot中混合斜体和常规字体的多行文本/标签
【发布时间】:2021-10-12 23:53:28
【问题描述】:

我尝试了几个选项来将重要性级别作为文本标签添加到绘图中。我使用 ggtext 包中的 geom_richtext() 得到了结果。尽管标签结果很好,但我将代码粘贴在图形/绘图上。知道如何避免这种情况!还是有其他选择?

geom_richtext(x = 1.15, 
                            y = 0.2, 
                            label.color = "black",
                            label = "<b>Significance Levels</b><br>ns <i>p</i> > 0.05<br>* <i>p</i> <= 0.05<br>** <i>p</i> <= 0.01<br>*** <i>p</i> <= 0.001<br>**** <i>p</i> <= 0.0001")[enter image description here][1]

【问题讨论】:

  • 如果您包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出,则会更容易为您提供帮助。
  • 由于我不是经验丰富的用户,因此不允许发布图表。这只是情节的标签。没有与数据相关联。

标签: r ggplot2 annotations


【解决方案1】:

试试这个:

library(gridtext)
library(ggplot2)

label <- "<b>Significance Levels</b><br>ns <i>p</i> > 0.05<br>* <i>p</i> <= 0.05<br>** <i>p</i> <= 0.01<br>*** <i>p</i> <= 0.001<br>**** <i>p</i> <= 0.0001"

ggplot(BOD, aes(Time, demand)) +
  geom_point() + 
  annotation_custom(richtext_grob(label), ymin = 0.2)

【讨论】:

  • 非常感谢 :)
猜你喜欢
  • 1970-01-01
  • 2020-05-19
  • 1970-01-01
  • 1970-01-01
  • 2020-10-11
  • 1970-01-01
  • 1970-01-01
  • 2017-05-22
  • 2016-08-10
相关资源
最近更新 更多