Skip to content

Commit

Permalink
markdown source builds
Browse files Browse the repository at this point in the history
Auto-generated via {sandpaper}
Source  : 5f66793
Branch  : main
Author  : Drake Asberry <[email protected]>
Time    : 2023-08-02 03:22:51 +0000
Message : Merge pull request #414 from albhasan/plot_lines_by_attribute_challenge

Fixes #374. Thanks to @sstevens2
  • Loading branch information
actions-user committed Aug 2, 2023
1 parent aa66aa8 commit ced4cee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
40 changes: 14 additions & 26 deletions 07-vector-shapefile-attributes-in-r.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,48 +675,36 @@ other lines can be black.

## Answers

First we need to make sure that the `BicyclesHo` attribute is a factor and
check how many levels it has.
First we explore the `BicyclesHo` attribute to learn the values that correspond
to the roads we need.


```r
lines_HARV$BicyclesHo <- as.factor(lines_HARV$BicyclesHo)
class(lines_HARV$BicyclesHo)
lines_HARV %>%
pull(BicyclesHo) %>%
unique()
```

```{.output}
[1] "factor"
[1] "Bicycles and Horses Allowed" NA
[3] "DO NOT SHOW ON REC MAP" "Bicycles and Horses NOT ALLOWED"
```

```r
levels(lines_HARV$BicyclesHo)
```

```{.output}
[1] "Bicycles and Horses Allowed" "Bicycles and Horses NOT ALLOWED"
[3] "DO NOT SHOW ON REC MAP"
```

Next, we will create a new object `lines_removeNA` that removes missing values.
Now, we can create a data frame with only those roads where bicycles and horses
are allowed.


```r
lines_removeNA <- lines_HARV[!is.na(lines_HARV$BicyclesHo),]
lines_showHarv <-
lines_HARV %>%
filter(BicyclesHo == "Bicycles and Horses Allowed")
```

In our plot, we will set colors so that only the allowed roads are magenta, and
we will set line width so that the first factor level is thicker than the
others.
Finally, we plot the needed roads after setting them to magenta and a thicker
line width.


```r
# First, create a data frame with only those roads where bicycles and horses
# are allowed
lines_showHarv <-
lines_removeNA %>%
filter(BicyclesHo == "Bicycles and Horses Allowed")

# Next, visualise using ggplot
ggplot() +
geom_sf(data = lines_HARV) +
geom_sf(data = lines_showHarv, aes(color = BicyclesHo), size = 2) +
Expand Down
2 changes: 1 addition & 1 deletion md5sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"episodes/04-raster-calculations-in-r.Rmd" "a100233c7c80bcae34c0112d10980d0d" "site/built/04-raster-calculations-in-r.md" "2023-08-01"
"episodes/05-raster-multi-band-in-r.Rmd" "cc2d67a1e5356d3684289205221a8233" "site/built/05-raster-multi-band-in-r.md" "2023-08-01"
"episodes/06-vector-open-shapefile-in-r.Rmd" "9966d5678aea06e445f5b660a079482e" "site/built/06-vector-open-shapefile-in-r.md" "2023-08-01"
"episodes/07-vector-shapefile-attributes-in-r.Rmd" "52357dcd467910c68d07bdade6b63242" "site/built/07-vector-shapefile-attributes-in-r.md" "2023-08-01"
"episodes/07-vector-shapefile-attributes-in-r.Rmd" "726f78cdabe6ebe90a609b31127674ca" "site/built/07-vector-shapefile-attributes-in-r.md" "2023-08-02"
"episodes/08-vector-plot-shapefiles-custom-legend.Rmd" "733bf768d8f27d9c7e548e7f835fda67" "site/built/08-vector-plot-shapefiles-custom-legend.md" "2023-08-01"
"episodes/09-vector-when-data-dont-line-up-crs.Rmd" "1234ba17924ba342d9b9cbbf04f77d91" "site/built/09-vector-when-data-dont-line-up-crs.md" "2023-08-01"
"episodes/10-vector-csv-to-shapefile-in-r.Rmd" "8aef2c986b83fd01b40fd0b4b8c1795c" "site/built/10-vector-csv-to-shapefile-in-r.md" "2023-08-01"
Expand Down

0 comments on commit ced4cee

Please sign in to comment.