【问题标题】:ggplot2: theme(axis.text=element_text(size=3) does not change font size on the y-axisggplot2: theme(axis.text=element_text(size=3) 不会改变 y 轴上的字体大小
【发布时间】:2021-09-16 09:26:18
【问题描述】:

使用此代码

FigureS8 <- plot(nonParametricBoot, "edge", plot = "difference", onlyNonZero = TRUE, order = "sample")

返回 x 和 y 轴上的文本标签太大的图形。

因此我添加了主题():

FigureS8 <- plot(nonParametricBoot, "edge", plot = "difference", onlyNonZero = TRUE, order = "sample")
FigureS8 + theme(axis.text=element_text(size=3))

现在 x 轴上标签上的字体大小变小(如我所愿),但 y 轴上的字体大小没有变化。如何更改两者的字体大小?

【问题讨论】:

  • 看起来您正在结合基础绘图和 ggplot 这可能会导致您的问题。此外,您可以尝试使用 axis.text.y 指定 y 轴设置。

标签: r ggplot2


【解决方案1】:

由于您没有在代码中指定要更改的轴,axis.text 被解释为仅适用于 x 轴,因为它始终是要处理的第一个轴。

因此代码应该是:

+ theme(axis.text.x = element_text(size = 3),
        axis.text.y = element_text(size = 3))

【讨论】:

    【解决方案2】:

    这可能是这个问题的一个实例:ggplot2 theme: axis.text not inheriting from text?

    您的主题需要“完整”才能让axis.text.y 正确地从axis.text 继承。所以要么定义一个完整的主题,要么只定义axis.text.x和axis.text.y

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 2019-12-17
      • 1970-01-01
      • 2012-10-29
      相关资源
      最近更新 更多