Is there a way of plotting global Warmth Index using WorldClim data in R?
For those not familiar with Warmth Index, it's an equation written by Yim & Kira to describe length and intensity of a growing period, see here: https://www.jstage.jst.go.jp/article/seitai/25/2/25_KJ00001775740/_pdf/-char/en
My example: I have a data set of locations for plant populations where I used WorldClim data to derive monthly mean temperature at each location, and have them described in a tibble:
## # A tibble: 5 x 18
## species latitude longitude temp_1 temp_2 temp_3 temp_4 temp_5 temp_6
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Magnol… 31.0 -91.5 9.05 11.1 15.5 19.6 23.1 26.3
## 2 Magnol… 35.7 -93.2 2.45 4.89 10.2 15.5 19.5 23.8
## 3 Magnol… 35.7 -93.2 2.45 4.89 10.2 15.5 19.5 23.8
## 4 Magnol… 43.2 -76.3 -5.33 -4.55 0.98 7.42 13.7 18.5
## 5 Magnol… 35.6 -92.9 2.45 4.89 10.2 15.5 19.5 23.8
## # … with 9 more variables: temp_7 <dbl>, temp_8 <dbl>, temp_9 <dbl>,
## # temp_10 <dbl>, temp_11 <dbl>, temp_12 <dbl>, valid_cells <dbl>,
## # warmth_index <dbl>, row_id <int>
The data is then reshaped from wide to long:
reshaped_data <- raw_data %>%
tidyr::gather(key = "month", value = "temp", temp_1:temp_12) %>%
mutate(month = stringr::str_remove(month, "temp_") %>% readr::parse_number(),
warm = case_when(temp > 5 ~ TRUE,
TRUE ~ FALSE))
Using Yim & Kira's equation, a colleague wrote the following to calculate the Warmth Index at each location:
warmth_index <- function(warm, temp){
warm_months <- sum(warm)
temp_sum <- sum(warm * temp) # when multiplied, the warm logical vector becomes 0 & 1
temp_sum - (5 * warm_months)
}
This equation allows me to calculate the Warmth Index using mean temperatures at specific locations, and it does this once I've reshaped all the data.
But my issue is this: I'd like to find all the places in the world where a similar Warmth Index is found. My guess is that I should use RasterStacks (e.g. https://www.benjaminbell.co.uk/2018/02/rasterstacks-and-rasterplot.html) to bundle all the WorldClim tiff files together and the calc() function, like you would to calculate Max or Min global temperature (e.g.
ma.t.MIN <- calc(ma.t.min, min)
ma.t.MAX <- calc(ma.t.max, max)
But I'm not sure how to apply the Warmth Index equation to a RasterStack as it relies upon a reshaped tibble, rather than tiffs in my project folder... any ideas how to do it? Ultimately I'd like to end up with a plot, showing the world graded by Warmth Index.