所需示例:使用箭头()和ggplot2 [英] Example Needed: Using arrow() with ggplot2

查看:147
本文介绍了所需示例:使用箭头()和ggplot2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



例如:我可以找到绘图的路径,例如:

 p <-ggplot(df,aes(x = x,y = y))
p + geom_point()+ geom_path()

现在我希望能够做到是指从路径中的一个元素到下一个元素的箭头。

如果能够告诉我如何平滑从路径中的一个元素到下一个元素的线条,可以使用额外的标记。

解决方案

geom_segment 有一个 code>参数。这里有一个简单的例子:

  library(grid)#需要箭头函数

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


$ arrow()函数需要b $ b

library(grid),参见这里


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.

解决方案

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.

这篇关于所需示例:使用箭头()和ggplot2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆