Skip to content

Commit 09451b4

Browse files
authored
Merge pull request #431 from Aariq/patch-3
Replace now superseded `gather()` with `pivot_longer()`
2 parents f053cc7 + 5ac4b80 commit 09451b4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

episodes/12-time-series-raster.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ xres(NDVI_HARV_stack)
187187
Once we have created our RasterStack, we can visualize our data. We can use the
188188
`ggplot()` command to create a multi-panelled plot showing each band in our
189189
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")
191191
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:
193193

194194
```{r plot-time-series}
195195
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")
197197
```
198198

199199
Now we can plot our data using `ggplot()`. We want to create a separate panel
@@ -228,7 +228,7 @@ we used above.
228228

229229
```{r ndvi-stack-wrap}
230230
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")
232232
233233
ggplot() +
234234
geom_raster(data = NDVI_HARV_stack_df , aes(x = x, y = y, fill = value)) +

0 commit comments

Comments
 (0)