Introduction to Mapping Geographic Data

HES 505 Fall 2024: Session 9

Carolyn Koehn

Objectives

  • By the end of today, you should be able to:

  • Describe the basic components of data visualization as a foundation for mapping syntax

  • Understand layering in both base plot and tmap

  • Make basic plots of multiple spatial data objects

Using plot

Packages with plot methods

  • Often the fastest way to view data

  • Use ?plot to see which packages export a method for the plot function

  • Or you can use ?plot.*** to see which classes of objects have plot functions defined

plot for sf objects

  • Can plot outlines using plot(st_geometry(your.shapefile)) or plot(your.shapefile$geometry)

  • Plotting attributes requires “extracting” the attributes (using plot(your.shapefile["ATTRIBUTE"]))

  • Controlling aesthetics can be challenging

  • layering requires add=TRUE

plot for sf objects

plot(st_geometry(cejst))

plot(cejst["EALR_PFS"])

plot for SpatRasters

plot(rast.data)

plot for SpatRasters

plot(rast.data["WHP_ID"], col=heat.colors(24, rev=TRUE))

Combining the two with add=TRUE

plot(rast.data["WHP_ID"], col=heat.colors(24, rev=TRUE))
plot(st_geometry(st_transform(cejst, crs=crs(rast.data))), add=TRUE)

Thinking about map construction

Grammar of Graphics (Wilkinson 2005)

  • Grammar: A set of structural rules that help establish the components of a language

  • System and structure of language consist of syntax and semantics

  • Grammar of Graphics: a framework that allows us to concisely describe the components of any graphic

  • Follows a layered approach by using defined components to build a visualization

  • ggplot2 is a formal implementation in R

Aesthetics: Mapping Data to Visual Elements

  • Define the systematic conversion of data into elements of the visualization

  • Are either categorical or continuous (exclusively)

  • Examples include x, y, fill, color, and alpha