In addition to the calculation of events, consecutive days over a given static threshold may be calculated with the exceedance()
function.
# Activate libraries
library(heatwaveR)
library(dplyr)
# Calculate exceedence
exc_25 <- exceedance(sst_WA, threshold = 25)
# Look at a few metrics
exc_25$exceedance %>%
ungroup() %>%
select(exceedance_no, duration, date_start, date_peak, intensity_mean, intensity_cumulative) %>%
dplyr::arrange(-intensity_cumulative) %>%
head(5)
## # A tibble: 5 x 6
## exceedance_no duration date_start date_peak intensity_mean
## <int> <int> <date> <date> <dbl>
## 1 7 52 2011-02-08 2011-02-28 1.67
## 2 6 25 2008-04-03 2008-04-14 0.980
## 3 10 41 2012-03-03 2012-04-10 0.439
## 4 2 17 1999-05-13 1999-05-22 0.856
## 5 5 10 2000-05-03 2000-05-04 0.697
## # ... with 1 more variable: intensity_cumulative <dbl>
Which, when plotted with ggplot2
code would look like this:
exc_25_thresh <- exc_25$threshold %>%
slice(9500:9866)
ggplot(data = exc_25_thresh, aes(x = t)) +
geom_flame(aes(y = temp, y2 = thresh, fill = "all"), show.legend = F) +
geom_line(aes(y = temp, colour = "temp")) +
geom_line(aes(y = thresh, colour = "thresh"), size = 1.0) +
scale_colour_manual(name = "Line Colour",
values = c("temp" = "black", "thresh" = "forestgreen")) +
scale_fill_manual(name = "Event Colour", values = c("all" = "salmon")) +
guides(colour = guide_legend(override.aes = list(fill = NA))) +
scale_x_date(date_labels = "%b %Y") +
labs(y = expression(paste("Temperature [", degree, "C]")), x = NULL)
The same function may be used to calculate consecutive days below a threshold, too.
exc_19 <- exceedance(sst_WA, threshold = 19, below = TRUE)
exc_19$exceedance %>%
dplyr::ungroup() %>%
dplyr::select(exceedance_no, duration, date_start, date_peak, intensity_mean, intensity_cumulative) %>%
dplyr::arrange(intensity_cumulative) %>%
head(5)
## # A tibble: 5 x 6
## exceedance_no duration date_start date_peak intensity_mean
## <int> <int> <date> <date> <dbl>
## 1 17 46 2003-09-06 2003-09-16 -0.601
## 2 16 31 2002-09-08 2002-09-25 -0.848
## 3 13 24 1997-09-03 1997-09-15 -0.769
## 4 20 25 2005-09-26 2005-10-12 -0.542
## 5 12 18 1997-08-13 1997-08-22 -0.694
## # ... with 1 more variable: intensity_cumulative <dbl>
And were one to desire a visualisation of these data it could be produced with the following code:
exc_19_thresh <- exc_19$threshold %>%
slice(1500:1866)
ggplot(data = exc_19_thresh, aes(x = t)) +
geom_flame(aes(y = thresh, y2 = temp), fill = "steelblue3", show.legend = F) +
geom_line(aes(y = temp, colour = "temp")) +
geom_line(aes(y = thresh, colour = "thresh"), size = 1.0) +
scale_colour_manual(name = "Line Colour",
values = c("temp" = "black", "thresh" = "forestgreen")) +
scale_y_continuous(limits = c(18, 23.5)) +
scale_x_date(date_labels = "%b %Y") +
labs(y = expression(paste("Temperature [", degree, "C]")), x = NULL)