Open and Plot Shapefiles in R
|
Shapefile metadata include geometry type, CRS, and extent.
Load spatial objects into R with the st_read() function.
Spatial objects can be plotted directly with ggplot using the geom_sf() function. No need to convert to a dataframe.
|
Explore and Plot by Shapefile Attributes
|
Spatial objects in sf are similar to standard data frames and can be manipulated using the same functions.
Almost any feature of a plot can be customized using the various functions and options in the ggplot2 package.
|
Convert from .csv to a Shapefile in R
|
Know the projection (if any) of your point data prior to converting to a spatial object.
Convert a data frame to an sf object using the st_as_sf() function.
Export an sf object as text using the st_write() function.
|
Intro to Raster Data in R
|
The GeoTIFF file format includes metadata about the raster data.
To plot raster data with the ggplot2 package, we need to convert it to a dataframe.
R stores CRS information in the Proj4 format.
Be careful when dealing with missing or bad data values.
|
Manipulate Raster Data in R
|
Use the crop() function to crop a raster object.
Use the extract() function to extract pixels from a raster object that fall within a particular extent boundary.
Use the extent() function to define an extent.
|