The package ggmap applies ggplot2 capabilities and grammar to Google Maps, OpenStreetMap, Stamen Maps, or CloudMade Maps. All of the geometries of ggplot2 are available, with the familiar appearance/features of popular map applications like Google Maps. There are 2 steps to using this package: download map raster (aka data in grid format, with each pixel corresponding to a particular geographic location) and then plot raster + data overlaying the map.
The ggmap package is dependent on ggplot2.
The ggmap package imports tibble, jpeg, rjson, scales, png, dplyr, strinr, httr, tidyr, RgoogleMaps, digest, glue, magrittr, purrr, plyr, and bitops.
The ggmap package is currently on version 3.0.0. There were mainly bug fixes between versions 1 and 2, whereas version 3 was created to address Google’s recent API requirements change that requires users to register with Google to use ggmap.
The get_map function downloads a map as an image and formats the image for plotting (the result is a specially classed raster object). The function takes in a variety of parameters including location, mapttype, source and color. If you plan on using the results of this function to create a plot with ggmap, this function must be executed first.
The ggmap function is the main function in the ggmap package. It takes the raster object created by the get_map function and creates a ggplot object which draws the map. You can use the typical ggplot layers to customize and add detail to your map. The function takes in a variety of parameters including ggmap, base_layer (which includes typical ggplot aes calls) and legend. Examples of ggmap can be found under the Examples of Usage section.
The geocode function accepts character strings and returns a data frame of geographic information. The default output is simple, which only includes latitude and longitude, but you can specify output=‘more’ as a parameter to get more in-depth location information. Below you will see location information for the University of Virginia.
The mapdist function provides distances for Google-determined routes and estimated duration. You must specify the locations from (first parameter) and to (second parameter). These can be physical addresses, landmarks or geographic coordinates. A useful parameter is mode, which can be set to driving, walking, cycling or transit. Changing the mode will change the estimated duration for the given route.
The qmap function provides a map around a landmark or city. Zoom is a useful parameter that will zoom in or out of the map. In addition, the maptype parameter allows you to specify the type of map in your output, suhc as hybrid, satellite, watercolor, etc. Below is a zoomed-in hyrbid map around the University of Virginia.
This map shows where in Seatle crime has occured, and overlaid over that map are markers of where the most dangerous neighborhoods are located.
This graph is a continuation of the previous graph. It filters the crime to the most dangerous crimes, then adds on a density plot accordingly.
The package Leaflet is similar in that it also allows you to create maps within R. It is used along with OpenStreetMap to make interactive maps and add information to the maps. You can add markers and tiles and render spatial objects onto the maps you create.
The main difference between ggmap and Leaflet is that Leaflet does not allow you to add in any stats that you calculate. The main purpose of Leaflet is to create maps that you want to visualize. It is, however, also much more dynamic than ggmap in that you can add interactivity and easily render spatial objects.
Tmap is a package is very similar to ggmap because it is based on the syntax of ggplot2. This allows it to have ease of use like ggmap, because it relies on a syntax that many people are already used to.
Tmaps allows you to create static or interactive maps, allowing you to see different information on the same map by using facets. You can also overlay tiles to represent information, like relative population size. It is also a useful tool for creating heatmaps. Importantly, the main difference between Tmaps and ggmaps is that Tmaps is more interactive and dynamic, allowing you to showcase more information on one map.
The MapView package allows for interactive visualizations of spatial data on maps. It is a package that is designed to handle very large amounts of data, which can be useful in specific data analyses. You can also toggle and get different information with queries by clicking on points on the maps that are created.
Again, the main difference between this package and ggplot is its level of interactivity and ability to see more information from the maps created.
The main pros of this package include:
Familiarity with ggplot language
Don’t need to know coordinates or full address
Can incorporate data points and information into the map
Depth of function capabilities
The two main cons of this package are as follows:
Some suggestions we have on features that could be added or tweaked are: * More interactivity and ability to layer would be useful for displaying more information at once
https://www.rdocumentation.org/packages/ggmap/versions/3.0.0/topics/get_map
https://www.rdocumentation.org/packages/ggmap/versions/3.0.0/topics/ggmap
https://www.rdocumentation.org/packages/ggmap/versions/2.6.1/topics/geocode
https://www.rdocumentation.org/packages/ggmap/versions/3.0.0/topics/mapdist
https://www.rdocumentation.org/packages/ggmap/versions/3.0.0/topics/qmap