【问题标题】:How to use angle in geom_label?如何在 geom_label 中使用角度?
【发布时间】:2017-12-21 09:27:16
【问题描述】:

我不确定如何在 geom_label 中使用 aes angle。我认为下面的这段代码会将标签旋转 45,但事实并非如此。

library(ggplot2)
ggplot(data = mtcars[1:4,]) +
  geom_label(aes(x = mpg, y = qsec, label=disp), angle = 45)

【问题讨论】:

  • @pogibas 请注意,您发布的链接涉及ggrepel::geom_text_repel(),而不是ggplot2::geom_label()。因此,即使该问题已成功关闭,ggplot2::geom_label() 仍然会忽略 angle

标签: r plot ggplot2


【解决方案1】:

显然这不适用于geom_label,但适用于geom_text

ggplot(data = mtcars[1:4,]) +
  geom_text(aes(x = mpg, y = qsec, label=disp), angle = 45)

来自?geom_text

目前 geom_label 不支持rot 参数,并且比geom_text 慢很多。

rot 显然是指旋转,并且似乎是不推荐使用的角度参数。

【讨论】:

    【解决方案2】:

    geom_text 不生成标签。你可以使用ggtext::geom_richtext

    library(ggplot2)
    library(ggtext)
    ggplot(data = mtcars[1:4,]) +
      geom_richtext(aes(x = mpg, y = qsec, label=disp), angle = 45)
    

    reprex package (v2.0.0) 于 2021-06-07 创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-30
      • 2015-10-19
      • 2020-05-13
      • 1970-01-01
      • 2016-04-27
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多