更改geom_spoke中箭头的方向 [英] Change direction of arrows in geom_spoke
问题描述
在 geom_spoke()
中有没有办法让箭头指向给定数据的方向?如果我有位置(x,y)和角度的数据,使用 geom_spoke
似乎是理想的选择,但我希望能够选择在哪个方向箭头应指向(远离坐标或指向它们;我想要后者)。
在本例中,我添加了 geom_point()
来说明数据的位置。半径是随机选取的,所以我想要箭头指向现在的点(当然不是点):
set.seed(1)
df < - expand.grid(x = 1:10,y = 1:10)
df $ angle < - runif(100,0,2 * pi)
ggplot(df,aes(x,y))+
geom_point()+
coord_equal()+
geom_spoke(aes(angle = angle) ,半径= 0.7,箭头=箭头(长度=单位(0.2,厘米)))
箭头
geom_spoke
引用 grid:arrow
,其中结束
参数:
last,
first
或both
,指示要绘制箭头的线的哪一端。
因为您没有明确设置 一个小例子: ends
参数,所以last的默认值$ c $
p <-ggplot(df,aes(x = x,y = y,angle = angle))+
geom_point()
结束
的默认值:
<$ p $ b $ lt; code>#省略ends参数,就像在你的尝试中一样:
p + geom_spoke(arrow = arrow(length = unit(0.2,cm)),radius = 0.7)
#或者明确写出ends参数:
p + geom_spoke(arrow = arrow(ends =last,length = unit(0.2,cm)),radius = 0.7)
在分段开始的箭头处,设置 Is there a way in In this example, I added The One of Because you didn't explicitly set the A small example: Default value of Arrow at the start of the segment, set 这篇关于更改geom_spoke中箭头的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! ends =first$ c
$ p $ p + geom_spoke(arrow = arrow(ends =first),radius = 0.7)
geom_spoke()
to get arrows to point to the direction of the given data? If I have data with a location (x,y) and an angle, it seems ideal to me to use geom_spoke
, but I would expect to be able to choose in which direction the arrows should point (away from the coordinates or pointing to them; I want the latter). geom_point()
to illustrate the location of my data; the radius is chosen randomly, so I want the arrow heads where the points are now (and instead of the points, of course):set.seed(1)
df <- expand.grid(x = 1:10, y=1:10)
df$angle <- runif(100, 0, 2*pi)
ggplot(df, aes(x, y)) +
geom_point() +
coord_equal() +
geom_spoke(aes(angle = angle), radius = 0.7, arrow=arrow(length = unit(0.2,"cm")))
arrow
in geom_spoke
refers to grid::arrow
, which has the ends
argument:
"last"
, "first"
, or "both"
, indicating which ends of the line to draw arrow heads.ends
argument, the default value of "last"
was used, i.e. arrow at the end of the segment.p <- ggplot(df, aes(x = x, y = y, angle = angle)) +
geom_point()
ends
:# omitting the ends argument, like in your attempt:
p + geom_spoke(arrow = arrow(length = unit(0.2, "cm")), radius = 0.7)
# or writing out the ends argument explicitly:
p + geom_spoke(arrow = arrow(ends = "last", length = unit(0.2, "cm")), radius = 0.7)
ends = "first"
:p + geom_spoke(arrow = arrow(ends = "first"), radius = 0.7)