@@ -32,10 +32,11 @@ library(sf)
32
32
33
33
``` {r load-data, echo=FALSE, results="hide"}
34
34
# learners will have this data loaded from previous episodes
35
- point_HARV <- st_read("data/NEON-DS-Site-Layout-Files/HARV/HARVtower_UTM18N.shp")
35
+ point_HARV <-
36
+ st_read("data/NEON-DS-Site-Layout-Files/HARV/HARVtower_UTM18N.shp")
36
37
lines_HARV <- st_read("data/NEON-DS-Site-Layout-Files/HARV/HARV_roads.shp")
37
- aoi_boundary_HARV <- st_read(
38
- "data/NEON-DS-Site-Layout-Files/HARV/HarClip_UTMZ18.shp")
38
+ aoi_boundary_HARV <-
39
+ st_read( "data/NEON-DS-Site-Layout-Files/HARV/HarClip_UTMZ18.shp")
39
40
```
40
41
41
42
:::::::::::::::::::::::::::::::::::::::::: prereq
@@ -490,33 +491,29 @@ other lines can be black.
490
491
491
492
## Answers
492
493
493
- First we need to make sure that the ` BicyclesHo ` attribute is a factor and
494
- check how many levels it has .
494
+ First we explore the ` BicyclesHo ` attribute to learn the values that correspond
495
+ to the roads we need .
495
496
496
497
``` {r}
497
- lines_HARV$BicyclesHo <- as.factor(lines_HARV$BicyclesHo)
498
- class(lines_HARV$ BicyclesHo)
499
- levels(lines_HARV$BicyclesHo )
498
+ lines_HARV %>%
499
+ pull( BicyclesHo) %>%
500
+ unique( )
500
501
```
501
502
502
- Next, we will create a new object ` lines_removeNA ` that removes missing values.
503
+ Now, we can create a data frame with only those roads where bicycles and horses
504
+ are allowed.
503
505
504
506
``` {r}
505
- lines_removeNA <- lines_HARV[!is.na(lines_HARV$BicyclesHo),]
507
+ lines_showHarv <-
508
+ lines_HARV %>%
509
+ filter(BicyclesHo == "Bicycles and Horses Allowed")
510
+
506
511
```
507
512
508
- In our plot, we will set colors so that only the allowed roads are magenta, and
509
- we will set line width so that the first factor level is thicker than the
510
- others.
513
+ Finally, we plot the needed roads after setting them to magenta and a thicker
514
+ line width.
511
515
512
516
``` {r harv-paths-bike-horses, fig.cap="Roads and trails in the area highlighting paths where horses and bikes are allowed."}
513
- # First, create a data frame with only those roads where bicycles and horses
514
- # are allowed
515
- lines_showHarv <-
516
- lines_removeNA %>%
517
- filter(BicyclesHo == "Bicycles and Horses Allowed")
518
-
519
- # Next, visualise using ggplot
520
517
ggplot() +
521
518
geom_sf(data = lines_HARV) +
522
519
geom_sf(data = lines_showHarv, aes(color = BicyclesHo), size = 2) +
0 commit comments