Objectives


Pre-lab assignments


Set-up

library(gstat)
library(tidyverse)
library(sp)
library(raster)

Our data

I’m using the precipitation data featured in the RSpatial pre-lab reading assignment. You can find the dataset here.

precip <- read.table("./data/precip.txt", sep = ",", header=T)
glimpse(precip)
## Observations: 456
## Variables: 17
## $ ID   <fctr> ID741, ID743, ID744, ID753, ID754, ID758, ID760, ID762, ...
## $ NAME <fctr> DEATH VALLEY, THERMAL/FAA AIRPORT, BRAWLEY 2SW, IMPERIAL...
## $ LAT  <dbl> 36.47, 33.63, 32.96, 32.83, 33.28, 32.82, 32.76, 33.74, 3...
## $ LONG <dbl> -116.87, -116.17, -115.55, -115.57, -115.51, -115.67, -11...
## $ ALT  <int> -59, -34, -31, -18, -18, -13, -9, -6, 2, 2, 3, 3, 3, 3, 4...
## $ JAN  <dbl> 7.4, 9.2, 11.3, 10.6, 9.0, 9.8, 9.0, 16.7, 106.3, 89.5, 6...
## $ FEB  <dbl> 9.5, 6.9, 8.3, 7.0, 8.0, 1.6, 7.0, 12.1, 107.1, 88.3, 65....
## $ MAR  <dbl> 7.5, 7.9, 7.6, 6.1, 9.0, 3.7, 5.0, 9.2, 72.9, 72.4, 49.6,...
## $ APR  <dbl> 3.4, 1.8, 2.0, 2.5, 3.0, 3.0, 1.0, 2.2, 32.1, 30.1, 22.5,...
## $ MAY  <dbl> 1.7, 1.6, 0.8, 0.2, 0.0, 0.4, 1.0, 1.3, 7.6, 2.0, 4.3, 1....
## $ JUN  <dbl> 1.0, 0.4, 0.1, 0.0, 1.0, 0.0, 0.0, 0.2, 2.2, 1.1, 1.3, 0....
## $ JUL  <dbl> 3.7, 1.9, 1.9, 2.4, 8.0, 3.0, 2.0, 3.5, 0.6, 0.6, 0.4, 3....
## $ AUG  <dbl> 2.8, 3.4, 9.2, 2.6, 9.0, 10.8, 9.0, 6.5, 0.6, 0.5, 1.7, 7...
## $ SEP  <dbl> 4.3, 5.3, 6.5, 8.3, 7.0, 0.2, 8.0, 6.4, 5.3, 1.4, 6.2, 8....
## $ OCT  <dbl> 2.2, 2.0, 5.0, 5.4, 8.0, 0.0, 8.0, 3.8, 11.4, 11.6, 6.0, ...
## $ NOV  <dbl> 4.7, 6.3, 4.8, 7.7, 7.0, 3.3, 7.0, 7.3, 47.8, 45.3, 33.6,...
## $ DEC  <dbl> 3.9, 5.5, 9.7, 7.3, 9.0, 1.4, 11.0, 7.4, 63.7, 58.0, 42.5...

Our dataset includes:

Let’s inspect this dataset by visualizing total annual precipitation across stations:

p <- precip %>% mutate(ANNUAL = rowSums(.[6:17])) %>% arrange(ANNUAL)
plot(p$ANNUAL, xlab = "Station ID", ylab = "Annual precipitation (mm)")

The bulk of our weather stations show annual precipitation under 500 millimeters (~20 inches in a year! And CA is where most of our food is grown… !?), with a few stations receiving higher precipitation. Seen another way:

hist(p$ANNUAL, 100)

It may also be interesting to look at how altitude and precipitation relate… here’s a quick visualization of the relationship between the two:

plot(p$ALT, p$ANNUAL, xlab = "Altitude (m above SL)", ylab = "Precipitation (mm)")