File tree 1 file changed +18
-2
lines changed
1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -46,15 +46,31 @@ elevs_by_soil$harv_dtmfull.tif
46
46
* I'll use `mutate` from `dplyr`
47
47
48
48
` ` ` r
49
- harv_soils <- mutate(harv_soils, elevation = elevs_by_soil$harv_dtmfull.tif)
49
+ harv_soils_elevs <- mutate(harv_soils, elevation = elevs_by_soil$harv_dtmfull.tif)
50
50
` ` `
51
51
52
+ * Or we can use `st_join`
53
+ * To do this we have to first convert `elevs_by_soil` into an `sf` object
54
+
55
+ ` ` ` r
56
+ elevs_by_soil <- st_as_sf(elevs_by_soil)
57
+ ` ` `
58
+
59
+ * And then join
60
+
61
+ ` ` ` r
62
+ harv_soils_elevs <- st_join(harv_soils, elevs_by_soil, join = st_equals)
63
+ ` ` `
64
+
65
+ * The `join = st_equals` indicates that we only want to match polygons that are the same
66
+ * `st_join` defaults to using `st_intersects`, which means that any polygons that touch each other will be match
67
+
52
68
* Once we done this then we can make maps using this information
53
69
* So let's plot the our soils map but colored by average elevation within the region
54
70
55
71
` ` ` r
56
72
ggplot() +
57
- geom_sf(data = harv_soils , mapping = aes(fill = elevation)) +
73
+ geom_sf(data = harv_soils_elevs , mapping = aes(fill = elevation)) +
58
74
scale_fill_viridis_c()
59
75
` ` `
60
76
You can’t perform that action at this time.
0 commit comments