Chapter 18 daymetr

The daymetr package can be used to download daymet climate data.

See here

And here

For some daymetr tutorials.

18.1 Install Packages

# Install and load required packages
# install.packages("daymetr") #uncomment here to install the package. 
library(daymetr)
library(tidyverse)

18.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 !!
  ) 

18.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.

18.4 Make a date column and plot max temperature.

df <- df %>% 
  mutate(date = as.Date(paste(year, yday, sep = "-"), "%Y-%j"))

df %>%
  filter(measurement == "tmax..deg.c.") %>%
  ggplot(aes(x = date, y = value)) +
  geom_line(color = "red") +
  theme_linedraw() +
  labs(y = "Max T (\u00b0C)", x = "")

18.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 = "")

18.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