Useful get_map() and ggmap() options

Visualizing Geospatial Data in R

Charlotte Wickham

Assistant Professor at Oregon State University

Changing the map image

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

 

By default, get_map() downloads a terrain image from Google maps

corvallis_map <- get_map(corvallis, zoom = 13, maptype = "terrain", source = "google")
Visualizing Geospatial Data in R

Other map image sources

?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")
Visualizing Geospatial Data in R

Specifying default data and aesthetics

?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()
Visualizing Geospatial Data in R

Specifying default data and aesthetics

?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)
Visualizing Geospatial Data in R

Specifying default data and aesthetics

?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)
Visualizing Geospatial Data in R

Specifying default data and aesthetics

?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)
Visualizing Geospatial Data in R

Changing the way the map is plotted

?ggmap
ggmap(ggmap, extent = "panel", base_layer, maprange = FALSE, legend = "right", 
      padding = 0.02, darken = c(0, "black"), ...)
  • extent: How much of the plotting area should the map take up?
  • maprange: Should the plot limits come from the map limits?
Visualizing Geospatial Data in R

Let's practice!

Visualizing Geospatial Data in R

Preparing Video For Download...