【问题标题】:In R, how to draw a line/path on Google Map relying two points?在 R 中,如何在谷歌地图上根据两点绘制一条线/路径?
【发布时间】:2017-02-05 15:05:55
【问题描述】:

我有以下使用谷歌地图库的 r 代码

library(ggmap)
map <- get_map(location = 'Asia', zoom = 4)
mapPoints <- ggmap(map)

我必须绘制两个点

mapPoints +
geom_point(aes(x = lon, y = lat, col = "orange"), data = airportD) 

现在我想在这些点之间画一条线,我怎样才能得到这个结果?

【问题讨论】:

标签: r google-maps-api-3 line ggmap


【解决方案1】:

这与向任何其他ggplot 对象添加层应该没有什么不同。

airports <- read.csv("https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat", header = TRUE)
names(airports) <- c("id", "name", "city", "country", "code",
                 "icao", "lat", "lon", "altitude", "timezone", "dst", "tz")
airportD <- airports[airports$city %in% c("Beijing", "Bangkok", "Shanghai"), ]

map <- get_map(location = 'Asia', zoom = 4)
mapPoints <- ggmap(map)

mapPoints +
  geom_point(aes(x = lon, y = lat), col = "orange", data = airportD)

mapPoints +
  geom_line(aes(x = lon, y = lat), col = "orange", data = airportD)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多