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).
library(raster)
library(sf)
library(sp)
library(spData)
library(tidyverse)
data(world) #load 'world' data from spData package
data = world %>% filter(continent != "Antarctica")
data = as(data,"Spatial")
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)
tmax_country = raster::extract(tmax_annual, data, fun = max, na.rm = T, small = T, sp = T, ) %>% st_as_sf()
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 |
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.