ggmap makes it easy to retrieve raster map tiles from popular online mapping services like google maps, open street maps, cloudmade and stamen:
library(ggmap)
(map <- get_map("pat neff hall", zoom = 15))
#> 1280x1280 terrain map image from Google Maps. see ?ggmap to plot it.
ggmap(map)
(extent <- bb2bbox(attr(map, "bb")))
#> left bottom right top
#> -97.13503 31.53403 -97.10756 31.55743
ggmap(get_stamenmap(extent, zoom = 15))
ggmap(get_stamenmap(extent, zoom = 15, maptype = "toner-background"))
Use qmplot()
in the same way you'd use qplot()
, but with a map automatically added in the background:
downtown <- subset(crime,
-95.39681 <= lon & lon <= -95.34188 &
29.73631 <= lat & lat <= 29.78400
)
qmplot(lon, lat, data = downtown, maptype = "toner-background", color = I("red"))
qmplot(lon, lat, data = downtown, maptype = "toner-lite", geom = "density2d", color = I("red"))
-
From CRAN:
install.packages("ggmap")
-
From Github:
devtools::install_github("dkahle/ggmap")