Session 1 Review
RStudio is a great IDE
Do your work in scripts (or Notebooks)
We almost always save values to variables:
pop_2010 <- 3200 * 0.03
You can see the data type of a variable with class()
:
class(pop_2010)
packages are the key to productivity with R
packages mainly provide additional functions (and sometimes data)
key packages for geospatial data include sf
and raster
the tidyverse is a family of packages that use piping syntax
install packages from the ‘Packages’ pane in RStudio, or install.packages()
load packages into memory with library()
to prevent clashes with duplicate function names, specify the package using the pkgname::
prefix (e.g., dplyr::filter()
), or indicate your preferences using the conflicted
package
sf data frames are essentially regular data frames with a ‘geometry’ column
import GIS data with: st_read(source, layer)
where source can be a:
layer is a named layer
view layers in a source with st_layers()
code to import Shapefiles, KMLs, GeoJSON, Geodatabase, GeoPackage
st_as_sf()
to convert plain data frames into sf data frames
plot()
works with sf objects
plot(ca_counties %>% st_geometry())
plot(ca_counties["col_name"])
tmap
makes nicer maps
tm_shape(yose_bnd_ll) +
tm_polygons() +
tm_shape(yose_hp_ll) +
tm_symbols() +
...
raster()
and brick()
to import raster files
crop()
to crop a raster
Make sure your working directory is the workshop folder, then:
Look in the ‘Files’ pane to make sure they’re there!
Don’t forget the complete the workshop evaluation at the end of today!