在R中,如何在Google地图上依靠两个点绘制line/path?
In R, how to draw a line/path on Google Map relying two points?
我有以下使用 Google 地图库的 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)
现在我想在这些点之间画一条线,我怎样才能得到这个结果?
这应该与向任何其他 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)
我有以下使用 Google 地图库的 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)
现在我想在这些点之间画一条线,我怎样才能得到这个结果?
这应该与向任何其他 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)