在R中显示不同颜色的GPS数据

在R中显示不同颜色的GPS数据,r,plot,R,Plot,我正在尝试绘制下面提到的图。我可以使用不同的颜色作为数据点,但如何像图中一样将箭头指向它们?。 我使用下面提到的语句。谢谢 plot(type ="o",c, d, xlab="longitude",ylab="latitude", main ="Path", col = 1:3); 您可以使用ggplot2中的geom_段生成绘图。 下面的代码显示了使用随机点的示例: require(ggplot2) df <- data.frame(x = rpois(10, 5), y

我正在尝试绘制下面提到的图。我可以使用不同的颜色作为数据点,但如何像图中一样将箭头指向它们?。 我使用下面提到的语句。谢谢

     plot(type ="o",c, d, xlab="longitude",ylab="latitude", main ="Path", col = 1:3);

您可以使用ggplot2中的geom_段生成绘图。 下面的代码显示了使用随机点的示例:

require(ggplot2)

df <- data.frame(x = rpois(10, 5), y = rpois(10, 5), group = 1:10)

g <- ggplot(df, aes(x = x, y = y, color = as.factor(group)))
g <- g + geom_segment(aes(xend=c(tail(x, n=-1), NA),
                          yend=c(tail(y, n=-1), tail(y, n = 1))),
                      arrow=arrow(length = unit(0.5, "cm")))
g <- g + theme_bw() + theme(legend.position="none") + xlab("longitude") + ylab("latitude") 
g
require(ggplot2)

df您可以使用ggplot2中的geom_段生成绘图。 下面的代码显示了使用随机点的示例:

require(ggplot2)

df <- data.frame(x = rpois(10, 5), y = rpois(10, 5), group = 1:10)

g <- ggplot(df, aes(x = x, y = y, color = as.factor(group)))
g <- g + geom_segment(aes(xend=c(tail(x, n=-1), NA),
                          yend=c(tail(y, n=-1), tail(y, n = 1))),
                      arrow=arrow(length = unit(0.5, "cm")))
g <- g + theme_bw() + theme(legend.position="none") + xlab("longitude") + ylab("latitude") 
g
require(ggplot2)

df请为一个可复制的例子添加一些数据请为一个可复制的例子添加一些数据非常感谢:)你好!我得到这个错误:错误:美学必须是长度1或与数据相同(464):xend,yend,x,y,颜色我正在使用我的数据,df非常感谢:)你好!我得到这个错误:错误:美学必须是长度1或与数据(464)相同:xend,yend,x,y,颜色我使用的数据,df