GGMap Overview
This package was created by Hadley Wickham, who published it in 2019. in GGmap extends the ggplot core features to create spatial and geographical visualizations to aid in spatial analysis. Visualization is a powerful tool in learning about trends in data. When relevant, ggmap allows users to put the data into the context it was collected. Essentially, it allows the background of a scatter plot, or any other graph (with axis latitude and longitude) to be a map. GGmap uses static maps from GoogleMaps, OpenStreetMap, Stamen Maps, or CloudMade Maps.
What you need to use it
Version History
The the current ggpmap is the 2nd version of the package, but the major difference between the two was bug fixes.
Imports
Dependencies:
RgoogleMaps, png, plyr, rjson, jpeg, digest, scales, dplyr, bitops, grid, glue, httr, stringr, purrr, magrittr, tibble, tidyr, as well as R version 3.1.0 or greater and ggplot2 version 2.2.0 or greater. Users must also register with google if they wish to take advantage of ggmaps extension to google maps.
Main Functions:
geocode:
Returns the longitude and latitude of a location the user inputs
main arguments:
- Location: The place the user wants more information about
Example:
get_map:
Literally gets the map of a string argument that user puts in. Does not print the map, user must store the get_map as an object to later insert into gg_map as the core argument.
main arguments:
Location (can be longitude and latitude, or an address)
Zoom ( an integer from 3(continent) to 21(building), the default is 10 (city))
Maptype : ptions available are “terrain”, “terrainbackground”, “satellite”, “roadmap”, and “hybrid” (google maps), “terrain”, “watercolor”, and “toner” (stamen maps), or a positive integer for cloudmade maps.
Source : User can specify source, options are Google Maps (“google”), OpenStreetMap (“osm”), Stamen Maps (“stamen”). If the user wants to use the google maps or any of these other services they must register and set up an API.
Color : color (“color”) or black-and-white (“bw”)
Language: for google maps only
Example
gg_map:
The function is similar to the ggplot function in ggplot 2, it creates the first layer where you can plot a ggmap object
main arguments:
Core argument: map that the data will be plotted on (usually done with get_map)
Extent: takes in “normal”, “device”, or “panel” (default) which states how much of the plot should the map take up
Legend: tells you where the legend will be placed, takes in “left”, “right” (default), “bottom”, “top”, “bottomleft”, “bottomright”, “topleft”, “topright”, “none” (used with extent = “device”)
Example
qmap:
Allows user to view a map around a known landmark or city name. It is an easy way to get a map of the general location a data needs to be plotted. Qmap is a wrapper function that does both the functions of ggmap and get_map to produce a quick map, hence the “q”.
main arguments:
Location: The user input, whatever location is desired
Zoom: specifies how magnified the map will be (1-21), on the same scale as get_map
Base Layer: A user can call on the gg_plot base layer in detail, to format the scatterplot aspect of the map
Example
Similar Packages:
ggplot2:
It is no surprise that these are similar, as they are heavily and rely on eachother. All of ggmap’s plotting capabilities come from ggplot. The major difference is the map layer that ggmap provides.
ggspatial:
ggspatial is very similar to ggmap, but it is only capable of data that is already in the form of a spatial object.
leaflet:
Leaflet to make interactive maps with Java Script. But doesn’t use google maps, it is in partnership with OpenStreetMap and MapBox. Can also be used with Shiny and R markdown.
# source (rstudio.github.io/leaflet/)
m <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
m # Print the map
GGMAP DEMO
Shiny applications not supported in static R Markdown documents
Conclusion:
| GGmap provides a quick and powerful option to get a map once it is set up. It can be very useful in certain scenarios like K-means clustering, or tracking a disease. |
The set up time of ggmap is higher compared to other packages because of its dependency on google. While the process is not difficult, it does exist |
Overally ggmap is a great option to get a map when it is needed.
Thank you for listening!
Sources: