@@ -187,13 +187,13 @@ xres(NDVI_HARV_stack)
187
187
Once we have created our RasterStack, we can visualize our data. We can use the
188
188
` ggplot() ` command to create a multi-panelled plot showing each band in our
189
189
RasterStack. First we need to create a data frame object. Because there are
190
- multiple columns in our data that are not variables, we will tidy (or "gather ")
190
+ multiple columns in our data that are not variables, we will tidy (or "pivot ")
191
191
the data so that we have a single column with the NDVI observations. We will
192
- use the function ` gather ()` from the ` tidyr ` package to do this:
192
+ use the function ` pivot_longer ()` from the ` tidyr ` package to do this:
193
193
194
194
``` {r plot-time-series}
195
195
NDVI_HARV_stack_df <- as.data.frame(NDVI_HARV_stack, xy = TRUE) %>%
196
- gather(variable, value, -(x:y))
196
+ pivot_longer( -(x:y), names_to = "variable", values_to = "value" )
197
197
```
198
198
199
199
Now we can plot our data using ` ggplot() ` . We want to create a separate panel
@@ -228,7 +228,7 @@ we used above.
228
228
229
229
``` {r ndvi-stack-wrap}
230
230
NDVI_HARV_stack_df <- as.data.frame(NDVI_HARV_stack, xy = TRUE) %>%
231
- gather(variable, value, -(x:y))
231
+ pivot_longer( -(x:y), names_to = "variable", values_to = "value" )
232
232
233
233
ggplot() +
234
234
geom_raster(data = NDVI_HARV_stack_df , aes(x = x, y = y, fill = value)) +
0 commit comments