Chapter 13 daymetr
The daymetr package can be used to download daymet climate data.
For some daymetr tutorials.
13.2 Download daymet for a specific location.
df <- download_daymet(
site = "Oak Ridge National Laboratories",
lat = 36.0133,
lon = -84.2625,
start = 2000,
end = 2010,
internal = TRUE,
simplify = TRUE # return tidy data !!
) ## Downloading DAYMET data for: Oak Ridge National Laboratories at 36.0133/-84.2625 latitude/longitude !
## Done !
13.3 Here are the daymet variables:
..$ year
..$ yday
..$ dayl..s.
..$ prcp..mm.day.
..$ srad..W.m.2.
..$ swe..kg.m.2.
..$ tmax..deg.c.
..$ tmin..deg.c.
..$ vp..Pa.
Those variables are: year, day of yeat, day length in seconds, precip in mm/day, solar radiation in w/m2, swe in kg/m2, tmax in C, tmin in C, and vapor pressure in Pascals.
13.4 Make a date column and plot max temperature.
## Warning: There were 2 warnings in `mutate()`.
## The first warning was:
## ℹ In argument: `date = as_date(paste(year, yday, sep = "-"),
## "%Y-%j")`.
## Caused by warning:
## ! `tz` argument is ignored by `as_date()`
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining
## warning.
df %>%
filter(measurement == "tmax..deg.c.") %>%
ggplot(aes(x = date, y = value)) +
geom_line(color = "red") +
theme_linedraw() +
labs(y = "Max T (\u00b0C)", x = "")## Warning: Removed 3413 rows containing missing values or values outside the
## scale range (`geom_line()`).

13.5 Do the same for radiation.
df %>%
filter(measurement == "srad..W.m.2.") %>%
ggplot(aes(x = date, y = value)) +
geom_line(color = "red") +
theme_linedraw() +
labs(y = "Solar radiation"~(W/m^2), x = "")## Warning: Removed 3413 rows containing missing values or values outside the
## scale range (`geom_line()`).

13.6 Stack 2 variables with patchwork.
Here is a refernce for special characters in ggplot axes labels
library(patchwork)
temp_plot <- df %>%
filter(measurement == "tmax..deg.c.") %>%
ggplot(aes(x = date, y = value)) +
geom_line(color = "red") +
theme_linedraw() +
labs(y = "Max T (\u00b0C)", x = "")
srad_plot <- df %>%
filter(measurement == "srad..W.m.2.") %>%
ggplot(aes(x = date, y = value)) +
geom_line(color = "red") +
theme_linedraw() +
labs(y = "Solar radiation"~(W/m^2), x = "")
srad_plot / temp_plot## Warning: Removed 3413 rows containing missing values or values outside the
## scale range (`geom_line()`).
## Removed 3413 rows containing missing values or values outside the
## scale range (`geom_line()`).
