Background and Objective

Environmental datasets containing information like climate are often stored as raster data. If you were to correspond temperature data stored in the raster format to specific spatial data/coordinates, you would need to extract the data from those coordinates from a raster temperature map.

This case study utilizes raster temperature data from WorldClim http://worldclim.org, which provides raster data for several climatic variables for locations around the world. This raster data will then be intersected with a set of polygons from the world dataset in order to determine the hottest country on each continent.

Data

data(world)
tmax_monthly <-getData(name = "worldclim", var="tmax", res=10)

Method

First, the continent Antarctica had to be filtered out of the world dataset because there is no raster data for Antarctica. Then the world dataet had to be converted to spatial data.

world_1 <- world %>%
  filter(continent != "Antarctica")

world_sp <- as(world_1, "Spatial")

Next, the WorldClim data, which was stored as tmax_monthly, was plotted to better understand the raster data

The tmax_monthly data then had to be converted into Celcius. Then the maximum of the monthly temperature maximums was taken, yielding the annual temperature maximums. Additionally, tmax_annual was renamed tmax for clarity.

tmax_monthly<-tmax_monthly*0.1

tmax_annual  <- max(tmax_monthly)

names(tmax_annual) <-"tmax"

To calculate the maximum temperature of each country raster data was extracted/intersected with the spatial data form the world dataset, then stored to sf format.

max_country <- raster::extract(tmax_annual, world_sp, fun=max, na.rm=T, small=T, sp=T)
max_country <- st_as_sf(max_country)

Results

The maximum temperature of each country is depicted in the following graph, while the hottest country on each continent is displayed in the table below.

country continent tmax
United States North America 44.8
Argentina South America 36.5
French Southern and Antarctic Lands Seven seas (open ocean) 11.8
Algeria Africa 48.9
Iran Asia 46.7
Spain Europe 36.1
Australia Oceania 41.8

Conclusion

By extracting climate data from the raster form and intersecting it a set of polygons, I was able to produce a graphic that communicated the maximum temperature of each country in a way that was easy to read and contextualized. Other relevant statistics, including the hottest country on each continent, could also be gleaned from the extracted raster data.