1

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.

Harry
  • 61
  • 6
  • 1
    Please add expected output for a given dataset. You can also add your data using `dput` function instead of pasting data directly – pogibas Jun 09 '19 at 10:11
  • @PoGibas sorry, the expected output would be a plot, showing how warmth index varies around the world. I'm trying to use r to do GIS, and would like to grade the plot from low to high Warmth Index. I've been using raster::plot with this methodology https://www.benjaminbell.co.uk/2018/02/rasterstacks-and-rasterplot.html but instead of temperature min/max/mean, I'd like plot Warmth Index – Harry Jun 09 '19 at 10:14
  • A simple heatmap will do. look here https://stackoverflow.com/questions/44662532/heat-map-of-earthquake-by-geocodes – M-- Jun 09 '19 at 10:33
  • @M-M I don't understand? The issue here is not about the locations but rather how to combine all the monthly average temperatures that WorldClim provides, apply a Warmth Index calculation to them and then plot the global Warmth Index for every location in the world... I don't think a heat map is what I'm after? Sorry not to be clearer earlier – Harry Jun 09 '19 at 10:40
  • @Harry You gotta clarify your question. I personally am having hard times understand it. Do not leave comments. [edit] and try to explain what exactly is desired and preferably show the steps and the final expected output – M-- Jun 09 '19 at 10:43

0 Answers0