【问题标题】:Displaying GPS data with different colors in R在 R 中以不同颜色显示 GPS 数据
【发布时间】:2017-08-04 21:30:12
【问题描述】:

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

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

【问题讨论】:

  • 请为可重现的示例添加一些数据

标签: r plot


【解决方案1】:

您可以使用 ggplot2 中的 geom_segment 生成绘图。 下面的代码展示了一个使用随机点的例子:

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

生成的图如下所示:

【讨论】:

  • 非常感谢 :) 美好的一天!
  • 我收到此错误:错误:美学必须是长度 1 或与数据 (464) 相同:xend、yend、x、y、颜色我正在使用我的数据,df
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-03
  • 2019-05-08
  • 1970-01-01
  • 2014-03-13
相关资源
最近更新 更多