實用的 get_map() 與 ggmap() 選項

在 R 視覺化地理空間資料

Charlotte Wickham

Assistant Professor at Oregon State University

更換地圖影像

library(ggmap)
corvallis <- c(lon = -123.2620, lat = 44.5646)

corvallis_map <- get_map(corvallis, zoom = 13, scale = 1)
Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=44.5646,-123.2
62&zoom=13&size=640x640&scale=1&maptype=terrain&language=en-EN&sensor=false

 

預設情況下,get_map() 會從 Google 地圖下載地形影像

corvallis_map <- get_map(corvallis, zoom = 13, maptype = "terrain", source = "google")
在 R 視覺化地理空間資料

其他地圖來源

?get_map
...
 maptype = c("terrain", "terrain-background", "satellite", "roadmap", "hybrid", 
            "toner", "watercolor", "terrain-labels", "terrain-lines", "toner-2010", 
            "toner-2011", "toner-background", "toner-hybrid", "toner-labels", 
            "toner-lines", "toner-lite"),
 source = c("google", "osm", "stamen"),
...
corvallis_map <- get_map(corvallis, zoom = 13, maptype = "toner-2010", source = "stamen")
在 R 視覺化地理空間資料

設定預設資料與美學對應

?ggmap
ggmap(ggmap, extent = "panel", base_layer, maprange = FALSE, legend = "right", 
      padding = 0.02, darken = c(0, "black"), ...)
ggplot(sales, aes(lon, lat)) +
  geom_point()
在 R 視覺化地理空間資料

設定預設資料與美學對應

?ggmap
ggmap(ggmap, extent = "panel", base_layer, maprange = FALSE, legend = "right", 
      padding = 0.02, darken = c(0, "black"), ...)
ggplot() +
  geom_point(aes(lon, lat), data = sales)
在 R 視覺化地理空間資料

設定預設資料與美學對應

?ggmap
ggmap(ggmap, extent = "panel", base_layer, maprange = FALSE, legend = "right", 
      padding = 0.02, darken = c(0, "black"), ...)
ggmap(corvallis_map) +
  geom_point(aes(lon, lat), data = sales)
在 R 視覺化地理空間資料

設定預設資料與美學對應

?ggmap
ggmap(ggmap, extent = "panel", base_layer, maprange = FALSE, legend = "right", 
      padding = 0.02, darken = c(0, "black"), ...)
ggmap(corvallis_map, base_layer = ggplot(sales, aes(lon, lat))) +
  geom_point() +

facet_wrap(~ condition)
在 R 視覺化地理空間資料

調整地圖的繪製方式

?ggmap
ggmap(ggmap, extent = "panel", base_layer, maprange = FALSE, legend = "right", 
      padding = 0.02, darken = c(0, "black"), ...)
  • extent:地圖要佔據多少繪圖區域?
  • maprange:圖的座標範圍要跟隨地圖範圍嗎?
在 R 視覺化地理空間資料

一起來練習吧!

在 R 視覺化地理空間資料

Preparing Video For Download...