co2 = read.table("co2_mm_mlo.txt",
col.names = c("year", "month", "decdate", "average", "interpolated", "trend", "ndays"))
AnnualCO2 = tapply(co2$interpolated, co2$year, mean)
AnnualYear = as.numeric(names(AnnualCO2))
mycols = ifelse(AnnualYear < 1960, "purple",
ifelse(AnnualYear < 1970, "blue",
ifelse(AnnualYear < 1980, "darkcyan",
ifelse(AnnualYear < 1990, "green",
ifelse(AnnualYear < 2000, "orange",
ifelse(AnnualYear < 2010, "red",
"brown"))))))
plot(AnnualYear, AnnualCO2,
col = mycols,
pch = 16,
xlab = "Year",
ylab = expression("Mean" ~ CO[2] ~ "(ppm)"),
main = expression("Annual Mean" ~ CO[2] ~ "Concentration"))
legend("topleft",
legend = c("1950s", "1960s", "1970s", "1980s",
"1990s", "2000s", "2010s"),
col = c("purple", "blue", "darkcyan", "green",
"orange", "red", "brown"),
pch = 16,
title = "Decade")Baby’s First Quarto
CO2 trends, 1958 - 2020
This report uses the NOAA ESRL dataset from Module 2 to highlight the increase in CO2 concentrations over 7 decades. Source: National Environmental Pro
The dataset shows a steady increase in atmospheric CO2 concentrations since 1958. Mean annual concentrations increased in every decade, and the magnitude of the increase generally became larger over time, particularly after 1990.
Plotting the annual CO2 concentration, with an emphasis on decadal increases
Mean CO2 concentration by decade
1950s 1960s 1970s 1980s 1990s 2000s 2010s
315.6076 320.2862 330.8544 345.5428 360.4614 378.5815 401.4693
The dataset shows a steady increase in atmospheric CO2 since 1958, with larger increases in later decades.
1960s 1970s 1980s 1990s 2000s 2010s
4.678583 10.568250 14.688417 14.918583 18.120083 22.887818
Module 3, Exercise 2 code
The assignment:
- Create a vector containing all CO2 concentrations for all years up to and including 1985 (Use the column headed ‘interpolated’ for the CO2 values)
- Create a vector containing all CO2 concentrations for all years following 1985
- Estimate the mean CO2 concentration for each of these vectors
- Convert the months in the CO2 data frame to factors and create a new column called ‘fmnth’ to store this in the data frame.
- Use the levels() and table() functions to a) make sure this worked, and b) see how many observations you have for each month.
co2 = read.table("co2_mm_mlo.txt",
col.names = c("year", "month", "decdate", "average", "interpolated", "trend", "ndays"))
names(co2)
#co2 concentration after 1985
Conc1 = subset(co2, year <= 1985)
Conc1
Vec1 = Conc1$interpolated
Vec1
Conc2 = subset(co2, year > 1985)
Conc2
Vec2 = Conc2$interpolated
Vec2
mean1 = mean(Vec1, na.rm = TRUE)
mean1
mean2 = mean(Vec2, na.rm = TRUE)
mean2
fmnth = factor(co2$month)
fmnth
levels(fmnth)
table(fmnth)