Map making — the art of cartography — is an ancient skill that involves communication, intuition, and an element of creativity. —Robin Lovelace, Jakub Nowosad, Jannes Muenchow, Geocomputation with R
Without Geography, You’re Nowhere
getting data
getting your data
To create maps in R, you’ll need to have geographic data to plot.
Those could come from shapefiles.
A shapefile will typically come to you as a zip file with a few files contained inside including at least some files with the .shp, .shx, .dbf extensions.
Another format that geographic data could come to you in is geojson, which will look something like this:
tigris is an R package that allows users to directly download and use TIGER/Line shapefiles
install.packages('tigris')library(tigris)library(ggplot2)manhattan_roads <-roads("NY", "New York")ggplot(manhattan_roads) +geom_sf() +theme_void()
sf
library(tidyverse)library(sf)# you might have some data in a shapefile -- # data/shapefile_unzipped/# -- cb_2013_us_county_20m.dbf# -- cb_2013_us_county_20m.prj# -- cb_2013_us_county_20m.shp# -- cb_2013_us_county_20m.shp.iso.xml# -- cb_2013_us_county_20m.shp.xml# -- cb_2013_us_county_20m.shx# -- county_20m.ea.iso.xmlcounties <-read_sf(here("data/shapefile_unzipped"))
sf
the payoff is that then you can use geom_sf() with ggplot2