簡體   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