LoginSignup
32
33

More than 5 years have passed since last update.

R で GoogleMaps にプロットする

Last updated at Posted at 2014-10-24

R で地図を書く方法はいくつかありますが,単にプロットしたいだけなら,Google Maps にプロットするのが楽そうです.

インストール

ggmap パッケージ (http://cran.r-project.org/web/packages/ggmap/index.html) をインストール

install.packages('ggmap')
library(ggmap)

マップ描画

中心座標を指定してマップオブジェクトを生成,描画します

map <- get_map(c(139.6917, 35.68949))
ggmap(map)

213db56cb364e21b28f602512db852d9.png

データをプロット

あらかじめ用意しておいた ↓ のような位置座標データをプロットしてみます

bd840252b8f998ae3f88ec864a94d77a.png

locations <- read.csv('locations.csv')
ggmap(map) + geom_point(data=locations, aes(x=経度, y=緯度), color='red')

326393f858be8dd504412e99eb02707c.png

日本全体をプロット

center <- geocode('kanazawa')
map <- get_map(c(center$lon, center$lat), zoom = 5, maptype = 'roadmap')
ggmap(map) + geom_point(data=locations, aes(x = geo_coordinates_1, y = geo_coordinates_0), color = 'red', size = 0.7)

geocode() 便利.

4c0d8bba79ca10af9419bd3fa51ef8af.png

中心座標を金沢にしたら収まりが良かったので,日本の中心は金沢.

32
33
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
33