Exercise 1:

Load in data

library(sf)
## Warning: package 'sf' was built under R version 4.0.5
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.5
countries <- st_read("./countries/countries.shp")
## Reading layer `countries' from data source `C:\Users\ctlan\Documents\School\Summer21\GEOG5680\Module12\countries\countries.shp' using driver `ESRI Shapefile'
## Simple feature collection with 177 features and 64 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -180 ymin: -90 xmax: 180 ymax: 83.64513
## CRS:           NA
options(scipen=10000)

Task 1, In the zipfile countries.zip is a global shapefile with various socio-economic indicators for different countries. Load this file into R and make plots of any two of the following variables (the variable names are given in brackets). Try different color scales and transformations of the data to get the most informative maps

ggplot() + 
  geom_sf(data = countries, aes(fill = pop_est)) + 
  theme_bw() + scale_fill_gradient(low = "yellow", high = "red", name = "Population")

ggplot() + 
  geom_sf(data = countries, aes(fill = gdp_md_est)) + 
  theme_bw() + scale_fill_gradient(low = "red", high = "green", name = "Median GDP") 

Exercise 2:

library(ncdf4)
library(raster)
## Warning: package 'raster' was built under R version 4.0.5
## Loading required package: sp
## Warning: package 'sp' was built under R version 4.0.5
air_temp <- raster("./air.mon.mean.nc", varname = "air")
air_temp
## class      : RasterLayer 
## band       : 1  (of  819  bands)
## dimensions : 73, 144, 10512  (nrow, ncol, ncell)
## resolution : 2.5, 2.5  (x, y)
## extent     : -1.25, 358.75, -91.25, 91.25  (xmin, xmax, ymin, ymax)
## crs        : NA 
## source     : air.mon.mean.nc 
## names      : Monthly.Mean.Air.Temperature.at.sigma.level.0.995 
## z-value    : 1948-01-01 
## zvar       : air
air_temp_stk <- stack("./air.mon.mean.nc", varname = "air")
tmp_avg <- cellStats(air_temp_stk, mean)
tmp_avg_ts <- ts(tmp_avg, start = c(1948, 1), freq = 12)
plot(tmp_avg_ts, col = "orange", xlab = "Time", ylab = "Average Temperature (C)", main = "Global Avg Air Temperature")