[英]In R, how to draw a line/path on Google Map relying two points?
I have the following r code using the Google Map library 我有以下使用Google Map库的r代码
library(ggmap)
map <- get_map(location = 'Asia', zoom = 4)
mapPoints <- ggmap(map)
I had to plot two points 我不得不画两点
mapPoints +
geom_point(aes(x = lon, y = lat, col = "orange"), data = airportD)
Now I want to draw a line between these points, how can I obtain this result? 现在,我想在这些点之间划一条线,如何获得该结果?
It shouldn't be any different than adding a layer to any other ggplot
object. 与向任何其他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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.