# I used some code from the creator of rasterVis to make a custom legend: First, we need to recognize it as a categorical raster using ratify(): We're going to use leveplot() from package rasterVis. # Alright, now let's make this plot pretty, working with 2016 data. # Now, we make a vector of all the values we have in our study area and select those from the legend object. # 20 wetlands 95 Emergent Herbaceous Wetlands #70A3BA # Love that. # 14 herbaceous 72 Sedge/Herbaceuous #C9C977 # 13 herbaceous 71 Grassland/Herbaceous #E2E2C1 # 7 barren 31 Barren Land (Rock/Sand/Clay) #B2ADA3 # 6 developed 24 Developed, High Intensity #AA0000 # 5 developed 23 Developed, Medium Intensity #ED0000 # 4 developed 22 Developed, Low Intensity #D89382 # 3 developed 21 Developed, Open Space #DDC9C9 This isn’t exactly trivial in R, but with a few steps, we can plot a land cover map with code that we can use forever and ever! # Load in the NLCD legend, colors and descriptions from package FedData. We want to visualize Routt County land cover in a manner consistent with other NLCD maps. National Land Cover Database has a standardized legend with specific colors that correspond to land cover classes. Making maps: Plotting an NLCD raster with the correct colors #Let's plot this stack and take a look at it. # If you want to get into regular expressions, there are entire books on it. # We can load in the NLCD series straight into a stack.I do this so often that I wrote a little function that takes a regular expression and creates a raster stack from the files that match it. # If they have the same resolution, extent and spatial reference, this is an easy way to conduct operations on multiple layers at the same time. The stack() function takes as many rasters as you give it and stacks them into one object. # values : 11, 95 (min, max) # We have seven different years of NLCD data. # source : C:/Users/ncinglis/Desktop/stbd/nlcd/nlcd_1.tif # crs : +proj=utm +zone=13 +datum=WGS84 +units=m +no_defs # What does a raster object look like in R? What are the key attributes of this data format? # Load a single raster using the raster() function This is the # install.packages(c("FedData", "rasterVis", "raster","sp", "rgdal", "reshape2", "treemapify", "ggplot2", "kableExtra", "animation" "scales")) # Install the following packages for this tutorial: Loading raster data # Set your working directory to the /data folder included in the repository using setwd().
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |