@@ -12,7 +12,8 @@ source("setup.R")
1212::::::::::::::::::::::::::::::::::::::: objectives
1313
1414- Build customized plots for a single band raster using the ` ggplot2 ` package.
15- - Layer a raster dataset on top of a hillshade to create an elegant basemap.
15+ - Use transparency to layer a raster dataset on top of a hillshade to create an elegant basemap.
16+ - Recognize the difference between a DTM and a DSM.
1617
1718::::::::::::::::::::::::::::::::::::::::::::::::::
1819
@@ -46,6 +47,9 @@ DSM_HARV_df <- as.data.frame(DSM_HARV, xy = TRUE)
4647See the [ lesson homepage] ( . ) for detailed information about the software,
4748data, and other prerequisites you will need to work through the examples in this episode.
4849
50+ We will be using ` dplyr ` , ` ggplot2 ` , and ` terra ` in this episode.
51+
52+ Make sure you have the ` DSM_HARV ` and ` DSM_HARV_df ` created.
4953
5054::::::::::::::::::::::::::::::::::::::::::::::::::
5155
@@ -154,7 +158,8 @@ terrain.colors(3)
154158```
155159
156160The ` terrain.colors() ` function returns * hex colors* -
157- each of these character strings represents a color.
161+ each of these character strings represents an earthy color
162+ that looks good on a landform map.
158163To use these in our map, we pass them across using the
159164` scale_fill_manual() ` function.
160165
@@ -170,33 +175,25 @@ ggplot() +
170175### More Plot Formatting
171176
172177If we need to create multiple plots using the same color palette, we can create
173- an R object (` my_col ` ) for the set of colors that we want to use. We can then
174- quickly change the palette across all plots by modifying the ` my_col ` object,
178+ an R object (` my_colors ` ) for the set of colors that we want to use. We can then
179+ quickly change the palette across all plots by modifying the ` mycolors ` object,
175180rather than each individual plot.
176181
177- We can label the x- and y-axes of our plot too using ` xlab ` and ` ylab ` .
178182We can also give the legend a more meaningful title by passing a value
179183to the ` name ` argument of the ` scale_fill_manual() ` function.
180184
185+ We can also turn off the labels of both axes by passing ` element_blank() ` to
186+ the relevant part of the ` theme() ` function.
187+
181188``` {r add-ggplot-labels}
182189
183- my_col <- terrain.colors(3)
190+ mycolors <- terrain.colors(3)
184191
185- ggplot() +
186- geom_raster(data = DSM_HARV_df , aes(x = x, y = y,
187- fill = fct_elevation_2)) +
188- scale_fill_manual(values = my_col, name = "Elevation") +
189- coord_quickmap()
190- ```
191192
192- Or we can also turn off the labels of both axes by passing ` element_blank() ` to
193- the relevant part of the ` theme() ` function.
194-
195- ``` {r turn-off-axes}
196193ggplot() +
197194 geom_raster(data = DSM_HARV_df , aes(x = x, y = y,
198195 fill = fct_elevation_2)) +
199- scale_fill_manual(values = my_col , name = "Elevation") +
196+ scale_fill_manual(values = mycolors , name = "Elevation") +
200197 theme(axis.title = element_blank()) +
201198 coord_quickmap()
202199```
@@ -221,12 +218,12 @@ Create a plot of the Harvard Forest Digital Surface Model (DSM) that has:
221218DSM_HARV_df <- DSM_HARV_df %>%
222219 mutate(fct_elevation_6 = cut(HARV_dsmCrop, breaks = 6))
223220
224- my_col <- terrain.colors(6)
221+ mycolors <- terrain.colors(6)
225222
226223ggplot() +
227224 geom_raster(data = DSM_HARV_df , aes(x = x, y = y,
228225 fill = fct_elevation_6)) +
229- scale_fill_manual(values = my_col , name = "Elevation") +
226+ scale_fill_manual(values = mycolors , name = "Elevation") +
230227 ggtitle("Classified Elevation Map - NEON Harvard Forest Field Site") +
231228 xlab("UTM Easting Coordinate (m)") +
232229 ylab("UTM Northing Coordinate (m)") +
@@ -289,6 +286,8 @@ transparent, 1 being opaque).
289286We can layer another raster on top of our hillshade by adding another call to
290287the ` geom_raster() ` function. Let's overlay ` DSM_HARV ` on top of the ` hill_HARV ` .
291288
289+ Let's not forget to use ` ggtitle ` to give our outputs some context.
290+
292291``` {r overlay-hillshade}
293292ggplot() +
294293 geom_raster(data = DSM_HARV_df ,
0 commit comments