Creating maps
One can use a map to visualize the geographical relationship of spatial data. Here, we introduce how to create a map from a shapefile with ggplot2
. Moreover, we introduce how to use ggmap
to download map data from an online mapping service.
Getting ready
Ensure you have installed and loaded ggplot2
into your R session. Please download all files from the following GitHub link folder:
How to do it…
Perform the following steps to create a map with ggmap
:
- First, load the
ggmap
andmaptools
libraries into an R session:> install.packages("ggmap") > install.packages("maptools") > library(ggmap) > library(maptools)
- We can now read the
.shp
file with thereadShapeSpatial
function:> nyc.shp ...
Get R for Data Science Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.