HES 505 Fall 2024: Session 9
Image Source: USGS
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
plotplot methodsOften 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 objectsCan 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 objectsplot for SpatRastersplot for SpatRastersadd=TRUEGrammar: 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
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
Scales map data values to their aesthetics
Must be a one-to-one relationship; each specific data value should map to only one aesthetic
tmaptmaptmapORDER MATTERS
cejst.proj <- st_transform(cejst, crs=crs(rast.data)) %>% filter(!st_is_empty(.))
states.proj <- st_transform(st, crs=crs(rast.data))
pal8 <- c("#33A02C", "#B2DF8A", "#FDBF6F", "#1F78B4", "#999999", "#E31A1C", "#E6E6E6", "#A6CEE3")
pt <- tm_shape(rast.data["category"]) +
tm_raster(palette = pal8) +
tm_shape(cejst.proj) +
tm_polygons(col = "EALR_PFS", n=10,palette=viridis(10),
border.col = "white") +
tm_shape(states.proj) +
tm_borders("red") +
tm_legend(outside = TRUE)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