2017-08-04 33 views
0

我想绘制下面提到的图。我可以使用不同的颜色作为数据点,但是我怎么能把箭头放在他们身上呢? 我正在使用下面提到的声明。由于在R中显示不同颜色的GPS数据

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

enter image description here

+0

请添加一些数据重复的例子很多:)祝天 – Niko

回答

2

可以生产使用geom_segment从GGPLOT2情节。下面 的代码显示了一个示例使用随机点:

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 

产生的情节是这样的:

enter image description here

+0

谢谢! – sara

+0

欢迎您:) – Niko

+0

我得到这个错误:错误:美学必须是长度为1或与数据相同(464):xend,yend,x,y,颜色 我正在使用我的数据,df < - 数据.frame(c,d,group = 1:length(c)) – sara

相关问题