Duke University
The first vignette introduces the data that alerted us to rapid CO2 increases in the atmosphere. Charles Keeling began monitoring atmospheric CO2 from atop Mauna Loa in 1958. The site was selected to be remote from local variation, aiming for a global perspective. It came to represent one of the most immediate and persuasive arguments that change is happening fast. The Mauna Loa CO2 data will provide an opportunity to work directly with the data that have been in media on climate change and its consequences.
Get started with R: work through the intro to R here
CO2 data from Mauna Loa trace buildup of greenhouse gasses. Work through this vignette and stop when you get to the section The Law Dome Ice Core Record (longer term trends that we’ll pick up on later).
This block of R code will extract long-term CO2 concentrations at the Mauna Loa observatory from the NOAA ftp site:
library( lubridate )
mw <- read.table('ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_weekly_mlo.txt')
# select columns and assign new names
mw <- mw[, c(1, 2, 3, 5)]
names(mw) <- c('year', 'month', 'day', 'co2ppm')
# date format
mw$date <- as.Date(paste(mw$year, mw$month, mw$day, sep = '-'), format = '%Y-%m-%d')
mw$time <- decimal_date( mw$date )
# retain necessary columns
mw <- mw[, c('date', 'year', 'time', 'co2ppm')]
# missing values
mw[mw$co2ppm == -999.99, ]$co2ppm = NA
Here are the first few rows:
| date | year | time | co2ppm |
|---|---|---|---|
| 1974-05-19 | 1974 | 1974.378 | 333.37 |
| 1974-05-26 | 1974 | 1974.397 | 332.95 |
| 1974-06-02 | 1974 | 1974.416 | 332.35 |
| 1974-06-09 | 1974 | 1974.436 | 332.20 |
| 1974-06-16 | 1974 | 1974.455 | 332.37 |
Make a plot:
par( mfrow = c(1,2), bty = 'n' )
plot(mw$date, mw$co2ppm, type = 'l',
xlab = 'Year', ylab = 'CO2 Concentration (ppmV)',
main = 'Mauna Loa Weekly' )
# annual averages
plot( mw$time, mw$co2ppm, type = 'l', col = 'grey', lwd = 2,
xlab = 'Year', ylab = '', main = 'Annual mean')
annual <- tapply( mw$co2ppm, mw$year, mean, na.rm = T )
lines( as.numeric( names( annual ) ), annual, col = 2, lwd = 2)
Here’s a plot of each year:
par( bty = 'n' )
plot( NA, xlim = c(0, 1), ylim = range( mw$co2ppm, na.rm=T ),
xlab = 'Month', ylab = 'ppmv', xaxt = 'n', las = 1 )
month <- seq(0, 12, by = 2 )
axis(1, at = month/12, labels = month )
years <- sort( unique( mw$year ) )
cols <- colorRampPalette( c('#d53e4f','#fc8d59','#fee08b',
'#e6f598','#99d594','#3288bd') )
cols <- cols( length(years) )
for( j in 1:length(years)){
wj <- which( mw$year == years[j] )
lines( mw$time[wj] - years[j], mw$co2ppm[wj], col = cols[j] )
}
Execute the last block of code line by line and comment each
line. This activity will require the help() function. You
will need to check each object with functions like head or
tail.
Explain what the graph means, including colors.