【问题标题】:How to change axis lines to arrows [duplicate]如何将轴线更改为箭头[重复]
【发布时间】:2020-06-30 22:07:49
【问题描述】:

编辑

如何将轴线更改为绘图上的箭头?

这是一个示例图,其中两个轴的末尾都应有箭头(来自用户 chemdork123's answer 的图)。

ggplot(mtcars, aes(mpg,disp)) + geom_point() + theme_minimal() 

【问题讨论】:

  • 您好,欢迎来到 SO!请务必在包含代码时包含您的数据集,以便每个人都复制您的问题。可以通过将dput(your.data.frame) 的输出作为代码粘贴到您的问题中来共享较小的数据集。或者,您可以随时使用 R 的内置数据集之一提出您的问题,例如 mtcarsiris 等。

标签: r ggplot2


【解决方案1】:

要将 x 或 y 轴表示为箭头,您可以访问这些对象的 theme() 元素。 This is a good place to go for information on the theme objects you can modify.

在这种情况下,您需要访问 axis.line(适用于所有轴)或 axis.line.xaxis.line.y 以分别访问 x 或 y 轴。必须通过调用element_line() 更改参数,然后在element_line() 中有一个arrow= 的参数,您可以在其中使用arrow() 函数来更改箭头的外观。

这是一个使用mtcars的示例:

ggplot(mtcars, aes(mpg,disp)) + geom_point() + theme_minimal() +
  theme(axis.line = element_line(arrow = arrow(type='closed', length = unit(10,'pt'))))

【讨论】:

    猜你喜欢
    • 2014-04-04
    • 2020-12-29
    • 2013-05-01
    • 2020-05-23
    • 2019-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    相关资源
    最近更新 更多