LeeModule6

Introduction

In this analysis, I used the GISS temperature anomaly dataset to calculate average annual temperature anomalies from monthly values. I then used conditional color coding to visualize how these anomalies have changed over time. Bars are colored purple for years before 1980 and orange for years from 1980 onward.

R Code and Explanation

I began by reading in the data and calculating annual mean temperature anomalies using tapply(). Then I used ifelse() to assign colors depending on whether each year is before or after 1980. Finally, I generated a vertical line plot (type = "h") to display the anomalies through time.

#Read in Data
giss = read.csv("./giss_temp.csv")

Unique years and annual means

# Unique years and annual means
allyears = unique(giss$Year)
ann_temp = tapply(giss$TempAnom, giss$Year, mean)

Color by year: before or after 1980

# Color by year: before or after 1980
mycols = ifelse(allyears >= 1980, "orange", "purple")

Plot

# Plot
plot(allyears, ann_temp, type = 'h',
     col = mycols, lwd = 3,
     xlab = "Year", ylab = "Temperature Anomaly",
     main = "Annual Temperature Anomalies Colored by Year Group")