繁体   English   中英

在R中,如何依靠两点在Google Map上画一条线/路径?

[英]In R, how to draw a line/path on Google Map relying two points?

我有以下使用Google Map库的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)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM