--- title: "Lab 2: Investigating Evidence for Climate Change, Part I: The Modern" author: "YOUR NAME HERE" date: "ADD DATE" output: html_document: theme: spacelab toc: true toc_depth: 2 number_sections: true toc_float: collapsed: false smooth_scroll: true --- ```{r setup, include=FALSE} # FOR STUDENTS CHANGE THESE SETTINGS TO TRUE SO THE OUTPUT OF ALL CODE CHUNKS WILL PRINT!!! # modify html output: # this code creates default chunk options and applies the same settings to all chunks in the document. The default can be modified in individual chunks. # code from: https://stackoverflow.com/questions/47710427/how-to-show-code-but-hide-output-in-rmarkdown/51409622 # modify universal code options here. knitr::opts_chunk$set(echo= FALSE, # TRUE to show code in HTML, FALSE to hide code eval= FALSE) # TRUE to evaluate code and display output in HTML, FALSE to suppress output ``` # Instructions This lab is in two parts: * PartI focuses on modern global temperature and atmospheric CO2 * PartII focuses on the Ice Core record with geologic history of temperature and CO2. PartII also includes the modern $\delta$ 13C atmospheric record for additional evidence of anthropogenic climate change. ## Setup * create a folder EcosystemEcology/Lab2 on your computer * download Lab2_AllData.xlsx and the .Rmd file to this folder! * Use 'save as' to save the file with a new name to create your own .Rmd and add your answers: + save as: Lab2_Assignment_partI_LASTnameFIRSTname.Rmd and .html ## Doing the lab * read through this assignment sheet so you know what the lab involves * choose whether you want to do the assignment with or without helper code * load data into R * Answer questions showing: + code + inserting supporting figures + provide explanations * for maximum points, answer in *full sentences* using appropriate *units*, *figure axis labels*, and descriptive *figure titles* * submit as .html (zipped if getting security error) and as .Rmd file in Blackboard * **IMPORTANT:** when you open the Rmd file in the first code chunk called {r setup, include = FALSE} change the settings to echo = TRUE and eval = TRUE to make sure your output shows. It needs to look like this: `knitr::opts_chunk$set(echo= TRUE, eval= TRUE)` ## DUE * part I: September 9 * part II: September 13 ## Background Questions Read the Lab2 Description to answer these questions: 1. Why does the *rate* of temperature change matter? 2. What is the warming threshold aboe which the IPCC warns there will be catastrophic climate change? 3. What region/latitudes of the Earth are warming most rapidly? 4. Why is Mauna Loa a good place to measure atmospheric CO2? 5. Have you heard of isotopes before? 6. Why is the ice record useful for understanding climate change? 7. What does a negative temperature anomaly tell you about the global temperature? # Lab Outline 1. **Activity A:** Determine current rates of air temperature and CO2 change from modern datasets 2. **Activity B:** Explore whether modern temperature and CO2 concentrations are related 3. **Activity C:** Compare current and pre-historical temperature and CO2 concentrations using data from the Vostok ice core 4. **Activity D:** Use modern atmospheric isotopic $\delta$ 13C data to examine supporting evidence that the current rise in CO2 comes from fossil fuel emissions # The Datasets: 1. Modern Global Temperature means and anomalies 2. Atmospheric CO2 concentrations from Mauna Loa 3. Atmospheric $\delta$ 13C signatures from Mauna Loa 4. Vostok Ice Core geologic record of global temperature and CO2 concentration # Load libraries and import data to R ## Load required libraries ```{r, load libraries, message=FALSE, error=FALSE, echo=TRUE, eval=TRUE} library(dplyr) library(ggplot2) library(readxl) # use install.packages("readxl") or install manually in Packages tab ``` ## Confirm your working directory The first step for opening data in R is to tell R which folder on your computer contains the data. The folder that R reads is called 'the working directory' or wd. You can use the command `getwd()` to find out which folder R is currently looking at. It will be easiest if you save the data and your .Rmd in the same folder because the default wd is the directory that your R script file comes from. If the data and .Rmd are in the same place, you won't need to change anything. Confirm that your wd is the folder where your data is saved: ```{r, check working directory} getwd() ``` ## Import the data OK, ready to import data. Read the data from the excel sheet by specifying which sheet and which line the data starts on. We're going to load all the data for the entire assignment in this step. I like to set-up my code this way, so that I can see all the data I plan to use by looking at the beginning of my R script. Each dataframe that we create should show up in your environment. ```{r, import all data, message=FALSE, echo = TRUE, eval=TRUE} setwd("/Users/memauritz/Desktop/R/R_programs/Teaching/EcosystemEcology_UTEP/Lab2_Data") modern.temp <- read_excel("Lab2_AllData.xlsx", sheet="GlobalTemperatureData_1880_2014", skip=2) modern.temp.anomaly <- read_excel("Lab2_AllData.xlsx", sheet="GlobalTempAnomaly_1880_2019", skip=1) modern.co2 <- read_excel("Lab2_AllData.xlsx", sheet="MaunaLoa_AnnualMean_CO2", skip=56) ``` ## Do a simple check to see whether the data imported correctly Use `%>% glimpse` to see the column names and the column type. All of our data is numeric so all the column types should be < dbl >. You can also check this in the excel file to see how R reads data. Modern Temperature data set: ```{r, view modern temperature, eval=TRUE} ``` Modern Temperature anomaly data set: ```{r, view modern temperature anomaly, eval=TRUE} ``` Modern CO2 concentration data set: ```{r, view modern CO2, eval=TRUE} ``` # An easy way to see column names When trying to remember the names of columns to graph or analyse your data, you can use `colnames(data)` anytime for a quick reminder of what's in a data frame. Eg: ```{r, colnames, echo=TRUE, eval=TRUE} colnames(modern.temp) ``` # Question Set ## **Activity A:** **Determine current rates of air temperature and CO2 change from modern datasets** ### Examine the absolute temperature record from 1880 - 2014: a. In modern.temp, the temperature column is called Temperature_F to indicate that temperature is reported in Fahrenheit. Use `mutate()` and the F to C conversion to calculate Celsius. We'll use Celsius because it is a scientific unit: $Temperature(C) = (Temperature(F) - 32) * \frac{5}{9}$ ```{r, calculate Temperature_C} # to save the new column to the modern.temp data frame, we have to assign it to an object using <- , here we'll just keep the same name: modern.temp <- # you can check that the new column was created (or open it from the Environment): modern.temp %>% glimpse ``` b. Create a graph showing the change in global temperature from 1880 to 2014. Add the data using `geom_point()` and `geom_line()`: ```{r, graph modern temp} ``` ### What is the rate of temperature change from 1880 to 2014, in Celsius? The rate of change is represented by the slope of a linear line fit. Recall the equation of a linear line: $y = mx + b$ Where **y** is the data on the y-axis, **x** is the data on the x-axis, **m** is the slope of the relationship, and **b** describes the intercept. Remember, the intercept will be in the units of the y-variable and the slope will be in units y/units x (ie: Celsius/year). The R function that fits a straight line is `lm(y ~ x, data)` **Answer the following:** a. What is the equation of the line? b. What is the rate of temperature change (with units)? (**hint: don't forget time in the units**) Fit a linear line to the temperature change over year 1880 to 2014: ```{r, fit lm to modern temperature} # fit a linear line using lm() and save the output to an object temp.change.line temp.change.lm <- ``` Display the result of the linear fit to find the value of the slope. One way to do this is by simply calling the object you just created with the line fit: ```{r, show lm output for modern temperature} ``` The output will show you the formula that was used to predict the line, and it will tell you the **(Intercept)** and **slope**. In R the slope is always given the name of the x-variable, in this case Year. ### Plot the rate of change line on top of the graph from part *6.1.1*. **Answer the following:** a. Based on the equation, and the figure, what would you conclude about global temperature change since 1880? b. The slope tells you the rate of change in y per 1 unit of x. Knowing that, use the slope to calculate how many degrees the temperature changed from 1880 to 2014? Show your code or write out your math. Plot the rate of change with the information from the lm() output (you can round to 3 significant figures) and add `+ geom_abline(intercept = , slope= )` to your ggplot. ```{r, plot modern temperature with lm regression line} ``` R can also do simple math, eg: ```{r, add in R} 1+2 ``` And: ```{r, multiply in R} 2*7 ``` ### What is the warming trend since 1950? The warming trend we see today is considered to have accelerated from the mid 1900's when the globalisation we recognise today started to grow. Calculate a new temperature trend-line that starts in 1950. You can do this by using filter to create a new dataset that starts in 1950, and fit a line. **Answer the following:** a. What is the equation of the line? b. What is the rate of temperature change since 1950 (with units)? (**hint: don't forget time in the units**) c. Compare the rate of change between 1880-2014 and 1950-2014. d. Do you have any concerns about the approach of graphing a straight line fit to the data from 1880-2014? Calculating rate of change since 1950: ```{r, calculate linear rate of change since 1950} modern.temp.1950 <- temp.change.lm.1950 <- ``` ### Make a figure with the anomaly data that extends to 2019, the most up-to-date annual data NASA GISS uses a baseline period from [1951-1980](https://climate.nasa.gov/vital-signs/global-temperature/). **Do the following:** a. graph the column Temp_anom_C in modern.temp.anomaly b. add accurate titles and axis labels c. add `+geom_hline(yintercept=0, colour="grey")` as a 0 reference to make it easier to distinguish negative and positive anomalies. d. add `+geom_segment(aes(x=1951, xend=1980, y=0, yend=0), colour="red")` to show the baseline period in your plot. **Answer the following:** e. How many degrees did the temperature change from the baseline year to 2019? f. How does the change you read from the anomaly figure compare to the temperature change you calculated from the linear slope between 1880-2014 in part *6.1.2*? Graph of modern temperature anomalies: ```{r, graph modern temp anomaly} ``` ## **Activity B:** **Explore whether modern temperature and CO2 concentrations are related** ### Plot a graph of modern CO2 vs time The data is in modern.co2, and we will use the Mean_co2 column which is the average annual atmospheric CO2 concentration in ppm. **Answer/do the following:** a. Graph the change in modern CO2 concentrations measured at Mauna Loa from 1950-2019 using point and line geom b. What is the equation of the line? c. What is the rate of temperature change since 1950 (with units)? (**hint: don't forget time in the units**) ```{r, graph modern CO2} ``` Calculate the rate of change: ```{r, calculate modern CO2 rate of change} co2.change.lm <- ``` ### Make a graph to show the relationship between temperature anomalies and atmospheric CO2 concentration. To do this, merge the temperature anomaly with the modern co2 data by Year. You can use the `merge()` or dplyr `inner_join()` functions. **Answer the following:** a. What is the relationship between atmospheric CO2 and the global temperature anomaly? b. Based on this relationship, what was the atmospheric CO2 concentration threshold when temperatures began to increase? Explain your answer. c. What would you conclude about the relationship between global mean temperature and atmospheric CO2? ```{r, graph modern co2 and temperature anomaly} temp.co2 <- ```