【问题标题】:R - different font sizes when using atopR - 使用 atop 时不同的字体大小
【发布时间】:2015-07-14 15:13:06
【问题描述】:

创建一个 y 轴有两条线的图。我使用的 atop 函数如下:

plot + ylab(expressions(atop("Line 1","Line 2")))

想知道是否可以更改第 1 行的字体大小,即使其大于第 2 行?

谢谢!

【问题讨论】:

  • 尝试嵌套的atop 函数。查看对this question 的回复。
  • 这行得通 - 谢谢!

标签: r ggplot2


【解决方案1】:

这是一种使用 plotmath scriptstyle 函数缩小字体特定部分的机制。还有另一个更小的版本。查看?plotmath 页面以获取绘图函数的完整列表。我不知道使字体变大的绘图策略。

plot + ylab(expression( atop(Line~1, 
                             scriptstyle(Line~2))
           ))

请注意,没有expressions 函数,我将您的文本转换为真正的 R 表达式。您可以查看 axis.title.y 的 element_text 功能的 theme() 设置以增加文本大小。

plot + ylab(expression( atop( Line~ 1,
                             scriptstyle( Line~ 2) ))) + 
       theme(axis.title.y = element_text( size = rel(2) ) )

【讨论】:

    【解决方案2】:

    除了plotmath,您可以直接使用grid函数绘制文本:

    library("gridExtra")
    gt <- grobTree(ggplotGrob(plot + ylab("")), textGrob("Line 1", 0.01, 0.5, rot = 90, gp = gpar(fontsize = 18)), textGrob("Line 2", 0.025, 0.5, rot = 90, gp = gpar(fontsize = 10)))
    plot.new()
    grid.draw(gt)
    

    【讨论】:

      猜你喜欢
      • 2019-04-13
      • 2017-09-29
      • 1970-01-01
      • 1970-01-01
      • 2020-09-02
      • 2017-05-31
      • 2011-11-27
      • 1970-01-01
      • 2014-08-24
      相关资源
      最近更新 更多