After completing this tutorial, you will be able to:
- Overlay 2 rasters in
Rto create a plot.
What You Need
RStudio to complete this tutorial. Also you should have an
earth-analytics directory set up on your computer with a
/data directory with it.
# load raster and rgdal libraries for spatial data library(raster) library(rgdal)
Overlay Rasters in R
Here, you will cover overlaying rasters on top of a hillshade for nicer looking plots in
R. To overlay a raster you will use the
add = T argument in the
plot() function. You will use alpha to adjust the transparency of one of your rasters so the terrain hillshade gives the raster texture! Also you will turn off the legend for the hillshade plot as the legend you want to see is the
DEM elevation values.
# open raster DTM data lidar_dem <- raster(x = "data/week-03/BLDR_LeeHill/pre-flood/lidar/pre_DTM.tif") # open dem hillshade lidar_dem_hill <- raster(x = "data/week-03/BLDR_LeeHill/pre-flood/lidar/pre_DTM_hill.tif") # plot raster data plot(lidar_dem_hill, main = "Lidar Digital Elevation Model (DEM)\n overlayed on top of a hillshade", col = grey(1:100/100), legend = FALSE) plot(lidar_dem, main = "Lidar Digital Elevation Model (DEM)", add = TRUE, alpha = .5)