2016-09-27 10 views
0

私は、次のRコードを持ってRで、どのように2つのポイントに頼るGoogleマップ上の行/パスを描画するには?

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

Googleマップライブラリを使用して、私は今、私はこれらの点の間に線を描きたい二点

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

をプロットしていた、どのように私はこの結果を得ることができます?

+0

[ggplotを使用してマップ内の2点を結ぶ]の可能な重複(http://stackoverflow.com/questions/26572663/connecting-2-points -in-a-map-using-ggplot) – SymbolixAU

答えて

2

他の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) 

enter image description here

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

enter image description here

関連する問題