Skip to content

Commit

Permalink
Update exercises before tackling #766
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Mar 18, 2022
1 parent 7b59c49 commit a28def3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion _04-ex.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@ data(nz_height, package = "spData")
E1. It was established in Section \@ref(spatial-vec) that Canterbury was the region of New Zealand containing most of the 100 highest points in the country.
How many of these high points does the Canterbury region contain?

**Bonus:** plot the result using the `plot()` function to show all of New Zealand, `canterbury` region highlighted in yellow, high points in Canterbury represented with black dots and


```{r 04-ex-e1}
library(tmap)
# tmap_mode("view")
qtm(nz) + qtm(nz_height)
canterbury = nz %>% filter(Name == "Canterbury")
canterbury_height = nz_height[canterbury, ]
nz_not_canterbury_height = nz_height[canterbury, , op = st_disjoint]
nrow(canterbury_height) # answer: 70
plot(nz$geom)
plot(canterbury$geom, col = "yellow", add = TRUE)
plot(nz_not_canterbury_height$geometry, pch = 4, col = "blue", add = TRUE)
plot(canterbury_height$geometry, pch = 3, col = "red", add = TRUE)
```

E2. Which region has the second highest number of `nz_height` points in, and how many does it have?
E2. Which region has the second highest number of `nz_height` points, and how many does it have?

```{r 04-ex-e2}
nz_height_count = aggregate(nz_height, nz, length)
Expand Down

0 comments on commit a28def3

Please sign in to comment.