Skip to content

Commit

Permalink
update intro
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejohnson51 committed Jul 6, 2023
1 parent 9aedaf3 commit d5ee9f5
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions vignettes/01-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -139,31 +139,27 @@ Getting multiple models results is also quite simple:
```{r}
models = c("BNU-ESM","CanESM2", "CCSM4")
climater_filter(id = "maca_day",
AOI = aoi_get(state = "CO"),
varname = 'tasmin',
model = models,
startDate = "2080-11-29" )
names(temp[[1]])
temp = getMACA(AOI = aoi_get(state = "CO"),
varname = 'tasmin',
model = models,
startDate = "2080-11-29")
temp$air_temperature$mean = app(temp$air_temperature, mean)
temp[[1]]$mean = app(temp[[1]], mean)
names(temp[[1]]) = c(models, "Ensemble Mean")
```

```{r, echo = FALSE, fig.width = 15}
# Plot
ggplot() +
geom_spatraster(data = temp$air_temperature) +
facet_wrap(~lyr) +
scale_fill_whitebox_c(
palette = "muted",
na.value = "white"
) + theme_minimal()
) +
theme_minimal()
```
If you don't know your models, you can always grab a random set by specifying a number:

Expand All @@ -172,7 +168,9 @@ random = getMACA(aoi_get(state = "MI"),
model = 3,
varname = "pr",
startDate = "2050-10-29")
```

```{r, echo = FALSE, fig.width = 15}
# Plot
ggplot() +
geom_spatraster(data = random$precipitation) +
Expand All @@ -192,7 +190,9 @@ Not all datasets are USA focused either. TerraClimate offers global, monthly dat
kenya = aoi_get(country = "Kenya")
tc = getTerraClim(kenya, varname = "pet", startDate = "2018-01-01")
chirps = getCHIRPS(kenya, startDate = "2018-01-01", endDate = "2018-01-04" )
```

```{r, echo = FALSE, fig.width = 15}
library(patchwork)
ggplot() +
Expand All @@ -213,24 +213,20 @@ ggplot() +
) +
geom_sf(data = kenya, fill = NA, lwd = 2, col = "black") +
theme_minimal()
```

# Point Based Data

Finally, data gathering is not limited to areal extents and can be retrieved as a time series at locations.

```{r}
AOI =
ts = getGridMET(geocode('Fort Collins', pt = TRUE),
varname = c("pr", 'srad'),
startDate = "2021-01-01",
endDate = "2021-12-31")
```

```{r}
```{r, echo = FALSE, fig.width = 15}
ggplot(data = ts, aes(x = date, y = srad)) +
geom_line() +
stat_smooth(col = "red") +
Expand Down Expand Up @@ -286,7 +282,7 @@ sites_stack = getTerraClim(AOI = cities,
endDate = "2018-12-31")
```

```{r}
```{r, echo = FALSE, fig.width = 15}
{
plot(sites_stack$tmax[[1]])
plot(vect(cities), add = TRUE, pch = 16, cex = .5)
Expand All @@ -302,9 +298,9 @@ sites_wide[[1]][1:5, 1:5]

To make the data 'tidy' simply pivot on the `date` column:

```{r,echo = FALSE}
```{r, echo = FALSE}
tmax = tidyr::pivot_longer(sites_wide[[1]], -date)
head(tmax)
ggplot(data = tmax, aes(x = date, y = value, color = name, group = name)) +
scale_color_viridis_d() +
Expand Down

0 comments on commit d5ee9f5

Please sign in to comment.