GISS Temperature Loops and If Statement

Author

Colby Hancey

##Introduction this is a report for the module 5 lab I use the GISS Northern Hemisphere temperature data (‘giss_temp.csv’) to loop through all the years and make individual monthly plots, and color code anomalies by whether they occur before or after 1980.

giss <- read.csv("giss_temp.csv")
head(giss)
  Year Month  DecDate TempAnom
1 1881     1 1881.042    -0.20
2 1881     2 1881.125    -0.24
3 1881     3 1881.208    -0.01
4 1881     4 1881.292    -0.05
5 1881     5 1881.375    -0.06
6 1881     6 1881.458    -0.32
years <- sort(unique(giss$Year))

for (yr in years) {
  yearID = which(giss$Year == yr)
  png(paste("giss_temp_", yr, ".png", sep=''))
  plot(giss$Month[yearID], giss$TempAnom[yearID],
       xlab="month", ylab="Temperature Anomaly")
  dev.off()
}
colors_1980 <- ifelse(giss$Year < 1980, "blue", "red")
plot(giss$Year, giss$TempAnom,
      col = colors_1980,
      pch = 16,
      xlab = "year",
      ylab = "Temperature Anomaly (\u00b0C)",
      main = "gISS Northern Hemisphere Anomalies: Pre- vs Post-1980")

abline(v = 1980, lty = 2, lwd = 2)