R GGPLOT2:如何将点与笛卡尔坐标中的箭头连接



我有兴趣使用GGPLOT2软件包在笛卡尔平面上学习如何将点与arrow()功能连接。

数据:

Coord = data.frame(x=c(2,-5,7),y=c(4,12,-78))
ggplot()+ coord_cartesian(xlim = c(-136,136), ylim = c(-6,210)) 

我尝试使用geom_segment,但我不确定如何继续。

我想学习如何将一个点连接到许多点?

我打算使用此方法为足球制作通过地图。

如果我正确理解您想要的内容,则需要在代表线路末端的数据框架中创建变量xendyend

df <- data.frame(x=c(2,-5,7),y=c(4,12,-78))
df$xend <- c(df$x[2:nrow(df)], NA)
df$yend <- c(df$y[2:nrow(df)], NA)
df <- df[1:(nrow(df)-1),]

geom_segment的情节:

ggplot(df)+ coord_cartesian(xlim = c(-136,136), ylim = c(-6,210))+
 geom_segment(aes(x=x,y=y, xend=xend, yend=yend))

更新:从一个点到多点:示例:

df <- data.frame(x=c(2,2,2,2,2),y=c(4,4,4,4,4), xend=c(34,3,12,100,-123), yend=c(18,-5,44,200,178))
ggplot(df)+ coord_cartesian(xlim = c(-136,136), ylim = c(-6,210))+
     geom_segment(aes(x=x,y=y, xend=xend, yend=yend))

最新更新