【问题标题】:getting constant text size while using atop function in r在r中使用atop函数时获得恒定的文本大小
【发布时间】:2019-04-13 14:37:28
【问题描述】:

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

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

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

library(ggplot2)

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

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

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

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

【问题讨论】:

    标签: r ggplot2 tidyverse plotmath


    【解决方案1】:

    我对剧情中的“替身”有点迷茫,但或许以下解决了问题:

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

    【讨论】:

    • 酷。不知道displaystyle(x)textstyle(x) 函数(有什么理由更喜欢前者而不是后者?)。我得到的行为是因为 plotmath 默认为 scriptstyle(x)scriptscriptstyle(x)?
    • @IndrajeetPatil,我立即选择了displaystyle,因为在 LaTeX 文档中,内联方程比显示方程小一些,而这正是解决问题的方法。现在看起来textstyle 的间距会小一些,所以你可能会看到你喜欢什么。我猜这里的默认值是scriptstyle,如果你添加了atop,它会是scriptscriptstyle
    • 谢谢。请参阅我对当前问题的第二部分:stackoverflow.com/questions/53239765/…也许您对此也有一些解决方案。
    猜你喜欢
    • 1970-01-01
    • 2014-01-30
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 2016-05-01
    • 1970-01-01
    • 2012-06-23
    • 2013-01-28
    相关资源
    最近更新 更多