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 setup 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, we will cover overlaying rasters on top of a hillshade for nicer looking plots in
R. To overlay a raster we will use the
add = T argument in the
plot() function. We will use alpha to adjust the transparency of one of our rasters so the terrain hillshade gives the raster texture! Also we will turn off the legend for the hillshade plot as the legend we 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=F) plot(lidar_dem, main = "Lidar Digital Elevation Model (DEM)", add = TRUE, alpha=.5)