Skip to content

Commit 9641b43

Browse files
authored
Merge pull request #486 from jonjab/timings
Timings
2 parents d345ea2 + 398ff56 commit 9641b43

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

episodes/02-raster-plot.Rmd

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
4647
See the [lesson homepage](.) for detailed information about the software,
4748
data, 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

156160
The `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.
158163
To 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

172177
If 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,
175180
rather than each individual plot.
176181

177-
We can label the x- and y-axes of our plot too using `xlab` and `ylab`.
178182
We can also give the legend a more meaningful title by passing a value
179183
to 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}
196193
ggplot() +
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:
221218
DSM_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
226223
ggplot() +
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).
289286
We can layer another raster on top of our hillshade by adding another call to
290287
the `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}
293292
ggplot() +
294293
geom_raster(data = DSM_HARV_df ,

episodes/03-raster-reproject-in-r.Rmd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ See the [lesson homepage](.) for detailed information about the software,
3535
data, and other prerequisites you will need to work through the examples in
3636
this episode.
3737

38+
We will be using only 3 libraries: `dplyr`, `ggplot2`, and `terra` in this episode.
39+
40+
41+
3842

3943
::::::::::::::::::::::::::::::::::::::::::::::::::
4044

@@ -297,7 +301,7 @@ hillshade to produce a nice looking, textured map!
297301

298302
::::::::::::::::::::::::::::::::::::::: challenge
299303

300-
## Challenge: Reproject, then Plot a Digital Terrain Model
304+
## Challenge: Reproject, then Plot a Digital Surface Model
301305

302306
Create a map of the
303307
[San Joaquin Experimental Range](https://www.neonscience.org/field-sites/field-sites-map/SJER)
@@ -343,6 +347,8 @@ ggplot() +
343347

344348
:::::::::::::::::::::::::
345349

350+
351+
346352
If you completed the San Joaquin plotting challenge in the
347353
[Plot Raster Data in R](https://datacarpentry.org/r-raster-vector-geospatial/02-raster-plot)
348354
episode, how does the map you just created compare to that map?
@@ -358,6 +364,7 @@ is this one was reprojected from WGS84 to UTM prior to plotting.
358364

359365
:::::::::::::::::::::::::
360366

367+
main
361368
::::::::::::::::::::::::::::::::::::::::::::::::::
362369

363370

0 commit comments

Comments
 (0)