The R package ggmap allows ggplot2 capabilities with google maps. I have recently used it for a few projects, and wanted to save a few quick sample plots so I can easily return to creating similar plots. Here are a few examples of ggmap plots.
The first example uses the ‘crime’ dataset that comes in the ggmap package. This dataset shows crimes in the Houston area.
require(ggmap) require(ggplot2) houston <- get_map(location = 'Houston', zoom = 10, maptype = "roadmap") ggmap(houston) + geom_point(data = crime[crime$offense == "murder",], mapping = aes(x = lon, y = lat), color="hotpink", shape=3, size=3) + ggtitle("ggmap example using\nthe crime R dataset") + theme(plot.title = element_text(hjust = 0.5))
This second plot is an example using the satellite plot type. This plot shows eathquakes near Fiji. The data is from the ‘quakes’ dataset in the R package ‘datasets’.
require(datasets) require(ggmap) require(ggplot2) fiji <- get_map(location = c(mean(quakes$long), mean(quakes$lat)), zoom = 5, maptype = "satellite") ggmap(fiji) + geom_point(data = quakes, mapping = aes(x = long, y = lat, color = depth, size=mag)) + scale_colour_gradient(low = "hotpink",high = "yellow") + ggtitle("ggmap example using\nthe Fiji earthquakes R dataset ") + theme(plot.title = element_text(hjust = 0.5))