Skip to content

Commit de1b68b

Browse files
author
Jon Jablonski
committed
PR changes in episode 7 and maintainers list.
1 parent 4189af5 commit de1b68b

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

episodes/07-vector-shapefile-attributes-in-r.Rmd

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ and other prerequisites you will need to work through the examples in this
4848
episode.
4949

5050

51+
5152
::::::::::::::::::::::::::::::::::::::::::::::::::
5253

5354
This episode continues our discussion of vector layer attributes and covers how
@@ -58,7 +59,7 @@ attribute values.
5859

5960
## Load the Data
6061

61-
We will continue using the `sf`, `terra` and `ggplot2` packages in this
62+
We will continue using the `sf`, `terra` `dplyr` and `ggplot2` packages in this
6263
episode. Make sure that you have these packages loaded. We will continue to
6364
work with the three ESRI `shapefiles` (vector layers) that we loaded in the
6465
[Open and Plot Vector Layers in R](06-vector-open-shapefile-in-r/) episode.
@@ -86,7 +87,7 @@ point_HARV
8687

8788
We can use the `ncol` function to count the number of attributes associated
8889
with a spatial object too. Note that the geometry is just another column and
89-
counts towards the total.
90+
counts towards the total. Let's look at the roads file:
9091

9192
```{r shapefile-attributes}
9293
ncol(lines_HARV)
@@ -215,7 +216,7 @@ connecting line thickness to a data variable.
215216

216217
```{r plot-subset-shapefile-unique-colors, fig.cap="Map of the footpaths in the study area where each feature is colored differently."}
217218
ggplot() +
218-
geom_sf(data = footpath_HARV, aes(color = factor(OBJECTID)), size = 1.5) +
219+
geom_sf(data = footpath_HARV, aes(color = factor(OBJECTID)), linewidth = 1.5) +
219220
labs(color = 'Footpath ID') +
220221
ggtitle("NEON Harvard Forest Field Site", subtitle = "Footpaths") +
221222
coord_sf()
@@ -250,7 +251,7 @@ Now let's plot that data:
250251

251252
```{r harv-boardwalk-map, fig.cap="Map of the boardwalks in the study area."}
252253
ggplot() +
253-
geom_sf(data = boardwalk_HARV, size = 1.5) +
254+
geom_sf(data = boardwalk_HARV, linewidth = 1.5) +
254255
ggtitle("NEON Harvard Forest Field Site", subtitle = "Boardwalks") +
255256
coord_sf()
256257
```
@@ -283,7 +284,7 @@ Now we can plot the data:
283284

284285
```{r harv-stone-wall-map, fig.cap="Map of the stone walls in the study area where each feature is colored differently."}
285286
ggplot() +
286-
geom_sf(data = stoneWall_HARV, aes(color = factor(OBJECTID)), size = 1.5) +
287+
geom_sf(data = stoneWall_HARV, aes(color = factor(OBJECTID)), linewidth = 1.5) +
287288
labs(color = 'Wall ID') +
288289
ggtitle("NEON Harvard Forest Field Site", subtitle = "Stonewalls") +
289290
coord_sf()
@@ -389,7 +390,7 @@ Now we can create our plot.
389390

390391
```{r harv-path-line-types, fig.cap="Roads and trails in the area with different line thickness for each type of paths."}
391392
ggplot() +
392-
geom_sf(data = lines_HARV, aes(size = TYPE)) +
393+
geom_sf(data = lines_HARV, aes(linewidth = TYPE)) +
393394
scale_size_manual(values = line_width) +
394395
ggtitle("NEON Harvard Forest Field Site",
395396
subtitle = "Roads & Trails - Line width varies") +
@@ -405,21 +406,17 @@ ggplot() +
405406
We can add a legend to our plot too. When we add a legend, we use the following
406407
elements to specify labels and colors:
407408

408-
- `bottomright`: We specify the location of our legend by using a default
409-
keyword. We could also use `top`, `topright`, etc.
410-
- `levels(objectName$attributeName)`: Label the legend elements using the
411-
categories of levels in an attribute (e.g., levels(lines\_HARV$TYPE) means
412-
use the levels boardwalk, footpath, etc).
413-
- `fill =`: apply unique colors to the boxes in our legend. `palette()` is the
414-
default set of colors that R applies to all plots.
415409

416410
Let's add a legend to our plot. We will use the `road_colors` object
417411
that we created above to color the legend. We can customize the
418412
appearance of our legend by manually setting different parameters.
419413

414+
415+
416+
420417
```{r add-legend-to-plot, fig.cap="Roads and trails in the study area using thicker lines than the previous figure."}
421418
ggplot() +
422-
geom_sf(data = lines_HARV, aes(color = TYPE), size = 1.5) +
419+
geom_sf(data = lines_HARV, aes(color = TYPE), linewidth = 1.5) +
423420
scale_color_manual(values = road_colors) +
424421
labs(color = 'Road Type') +
425422
ggtitle("NEON Harvard Forest Field Site",
@@ -435,7 +432,7 @@ parameters.
435432

436433
```{r modify-legend-plot, fig.cap="Map of the paths in the study area with large-font and border around the legend."}
437434
ggplot() +
438-
geom_sf(data = lines_HARV, aes(color = TYPE), size = 1.5) +
435+
geom_sf(data = lines_HARV, aes(color = TYPE), linewidth = 1.5) +
439436
scale_color_manual(values = road_colors) +
440437
labs(color = 'Road Type') +
441438
theme(legend.text = element_text(size = 20),
@@ -449,7 +446,7 @@ ggplot() +
449446
new_colors <- c("springgreen", "blue", "magenta", "orange")
450447
451448
ggplot() +
452-
geom_sf(data = lines_HARV, aes(color = TYPE), size = 1.5) +
449+
geom_sf(data = lines_HARV, aes(color = TYPE), linewidth = 1.5) +
453450
scale_color_manual(values = new_colors) +
454451
labs(color = 'Road Type') +
455452
theme(legend.text = element_text(size = 20),
@@ -516,7 +513,7 @@ line width.
516513
```{r harv-paths-bike-horses, fig.cap="Roads and trails in the area highlighting paths where horses and bikes are allowed."}
517514
ggplot() +
518515
geom_sf(data = lines_HARV) +
519-
geom_sf(data = lines_showHarv, aes(color = BicyclesHo), size = 2) +
516+
geom_sf(data = lines_showHarv, aes(color = BicyclesHo), linewidth = 2) +
520517
scale_color_manual(values = "magenta") +
521518
ggtitle("NEON Harvard Forest Field Site",
522519
subtitle = "Roads Where Bikes and Horses Are Allowed") +
@@ -562,7 +559,7 @@ Now we can create our plot:
562559

563560
```{r colored-state-boundaries, fig.cap="Map of the continental United States where the state lines are colored by region."}
564561
ggplot() +
565-
geom_sf(data = state_boundary_US, aes(color = region), size = 1) +
562+
geom_sf(data = state_boundary_US, aes(color = region), linewidth = 1) +
566563
scale_color_manual(values = colors) +
567564
ggtitle("Contiguous U.S. State Boundaries") +
568565
coord_sf()

index.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
---
2-
maintainers:
3-
- Leah Wasser
4-
- Jemma Stachelek
5-
- Tyson Swetnam
6-
- Lauren O'Brien
7-
- Janani Selvaraj
8-
- Lachlan Deer
9-
- Chris Prener
10-
- Juan Fung
2+
113
site: sandpaper::sandpaper_site
124
---
135

0 commit comments

Comments
 (0)