Objective

In this case study we’ll work with a timeseries of temperature data from WorldClim (http://worldclim.org).These are near-global rasters of various climatic variables available at several resolutions. For convenience, we’ll work with the very coarse data (10 minutes, which is about 10km), but much finer data are available (~1km).

Data & Methods

  1. Load packages and world data.
library(raster)
library(sf)
library(sp)
library(spData)
library(tidyverse)

data(world) #load 'world' data from spData package
  1. Prepare country polygon data.
data = world %>% filter(continent != "Antarctica")
data = as(data,"Spatial")
  1. Prepare climate data. We use WorldClim’s maximum temperature dataset at resolution 10 degrees. We will convert the values to degrees C. Then we create tmax_annual that contains the annual max temperature in each pixel to create a single layer that contains the maximum temperature in each location.
tmax_monthly <-getData(name = "worldclim", var = "tmax", res=10)
tmax_monthly  #inspect the data
plot(tmax_monthly)
tmax_monthly = tmax_monthly / 10
tmax_annual = max(tmax_monthly)
names(tmax_annual) = "tmax"
plot(tmax_annual)
  1. Calculate the maximum temperature observed in each country. We use raster::extract() in tmax_annual and data to find the max temperature in each country using fun = max. Then we converted this into sf format.
tmax_country = raster::extract(tmax_annual, data, fun = max, na.rm = T, small = T, sp = T, ) %>% st_as_sf()

Results

We used ggplot functions to plot the maximum temperature by country onto a map of the world. Then we made a table using dplyr functions to show the hottest country of each continent.

ggplot(data) + 
  geom_sf(data = tmax_country, mapping = aes(fill = tmax)) + 
  scale_fill_viridis_c(name="Annual\nMaximum\nTemperature (C)") + 
  theme(legend.position ='bottom')

hottest_countries = tmax_country %>% 
  st_set_geometry(NULL) %>% 
  group_by(continent) %>% arrange(tmax) %>% 
  top_n(n = 1) %>% 
  select("Name" = name_long, "Continent" = continent, "Max Temp" = tmax) %>% 
  knitr::kable()
hottest_countries
Name Continent Max Temp
French Southern and Antarctic Lands Seven seas (open ocean) 11.8
Spain Europe 36.1
Argentina South America 36.5
Australia Oceania 41.8
United States North America 44.8
Iran Asia 46.7
Algeria Africa 48.9

Conclusion

By manipulating raster data containing temperature values across the world, we were able to find the maximum temperature of each country and then plot it to show where the hottest countries of each continent are. By generating a table containing these hottest countries, we can see that Europe’s hottest country is Spain, North America’s is USA, South America’s is Argentina, and so on. The hottest country in the world is Algeria in Africa with a maximum annual temperature of 48.9 C.