所需示例:将 arrow() 与 ggplot2 一起使用

发布于 2024-09-13 15:47:02 字数 279 浏览 3 评论 0原文

我想创建一个 geom_path() ,它的箭头指向路径中的下一个位置。

我可以毫无问题地获取绘图路径,例如:

df <- (x=1:12, y=20:31, z=1:12)
p <- ggplot(df, aes(x=x, y=y))
p + geom_point() + geom_path()

现在我想要做的是绘制从路径中的一个元素到下一个元素的指向箭头。

如果您能告诉我如何平滑从路径中的一个元素到下一个元素的线条,请加分。

I'd like to create a geom_path() that has arrows pointing towards the next location in the path.

I can get the path to plot, without issue, for example:

df <- (x=1:12, y=20:31, z=1:12)
p <- ggplot(df, aes(x=x, y=y))
p + geom_point() + geom_path()

Now what I'd like to be able to do is plot that point arrows from one element in the path to the next.

Extra marks if you could tell me how to smooth the lines from one element in the path to the next.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-09-20 15:47:02

geom_segment 有一个 arrow 参数。这是一个简短的示例:

library(grid) # needed for arrow function

p <- ggplot(df, aes(x=x, y=y)) +
     geom_point() +
     geom_segment(aes(xend=c(tail(x, n=-1), NA), yend=c(tail(y, n=-1), NA)),
                  arrow=arrow(length=unit(0.3,"cm")))

arrow()< 需要 library(grid) /code> 函数,请参阅此处

geom_segment has an arrow argument. Here's a short example:

library(grid) # needed for arrow function

p <- ggplot(df, aes(x=x, y=y)) +
     geom_point() +
     geom_segment(aes(xend=c(tail(x, n=-1), NA), yend=c(tail(y, n=-1), NA)),
                  arrow=arrow(length=unit(0.3,"cm")))

library(grid) is needed for arrow() function, see here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文