在r中使用atop函数时获得恒定的文本大小

Ind*_*til 5 r ggplot2 plotmath tidyverse

下面是我编写的复杂自定义函数的一个简单得多的示例。在这个函数的全长形式中,

  • "layer1"对应于caption用户输入,
  • "layer2" 对应于统计测试的结果,并且
  • "layer3" 对应于有关执行的统计测试的详细信息。

但是当所有三层都包含在标题中时,它看起来像这样 -

library(ggplot2)

ggplot(iris, aes(Species, Sepal.Length)) +
  geom_boxplot()  +
  labs(caption = substitute(atop(substitute(
    atop("layer1", "layer2")
  )
  , "layer3")))
Run Code Online (Sandbox Code Playgroud)

reprex 包(v0.2.1)于 2018 年 11 月 9 日创建

所以我想找出一种方法可以使所有三层文本大小保持不变。我实际上不确定为什么在这种情况下文本大小会自动更改。

有什么办法可以防止这种情况发生吗?

Jul*_*ora 4

我对情节中的“替代品”有点困惑,但也许以下可以解决问题:

ggplot(iris, aes(Species, Sepal.Length)) +
  geom_boxplot()  +
  labs(caption = substitute(atop(
    atop(displaystyle("layer1"), displaystyle("layer2")), "layer3")))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • @IndrajeetPatil,我立即采用了“displaystyle”,因为在 LaTeX 文档中,内联方程比显示方程小一些,而这正是修复它的方法。现在看起来“textstyle”的间距会稍微小一些,所以你可能会看到你喜欢的。我猜这里的默认值是“scriptstyle”,如果您添加“atop”,它将是“scriptscriptstyle”。 (2认同)