Data Viz in R: Week 4
R Markdown files contain
Sometimes we want to annotate the figure directly
annotate()
!
Projection: “The challenge in map-making is that we need to take the spherical surface of the earth and flatten it out so we can display it on a map.”
EPSG (European Petroleum Survey Group) and ESRI (Environmental Systems Research Institute) maintain registries of projections. Several sites provide convenient access to registered projections, including http://spatialreference.org/ and https://epsg.io/.
Coordinates can only be placed on the Earth’s surface when their coordinate reference system (CRS) is known. The CRS includes both the projection and extent of the map. ggplot will use the coordinate system of the data
coord_sf
to change the CRS when plottingst_transform
to convert data frames to a different CRSMapping sequential colors to quantities to show variance across locations produces a choropleht map.
SF represents simple features as records in a data.frame or tibble with a geometry list-column. To learn more: r-spatial.github.io/sf
The simple features are in the way geometry is represented. The geometry types include:
Some notes on installation
Joins merge data sets based on key variables. The syntax is always name_join(x, y, by = "key")
Animated visuals created by Garrick Aden-Buie
full_join()
: keeps all observations in x and yleft_join()
: keeps all observations in xThere’s a good chance we won’t get to this, but Leaflet is one of the most popular open-source JavaScript libraries for interactive maps. RStudio has created a package to integrate and generate Leaflet maps in R.
Today’s script has an example meant to walk you though a few key bits.