---
title: "Lab 2: Global Dams Data"
author: "ENS-215"
date: "Winter 2023"
output:
  html_document:
    df_print: paged
    theme: spacelab
    toc: yes
    toc_float: yes
---

<br/>

## Overview
For thousands of years human civilization has relied on dams for flood control, water supply, irrigation, navigation, and hydropower.  Dams and reservoirs have long been in use, however the past century has seen a dramatic increase in their number as populations have grown and development has spread around the globe.  

While dams and reservoirs can provide significant benefits to society, they nonetheless disrupt the natural flow regime of rivers and can have a host of negative environmental and social impacts.  These negative impacts include (but are not limited to) significant methane emissions from reservoirs, disruption of stream and riparian ecosystems, changes in sediment delivery downstream, and displacement of communities around the dam/reservoir.  

Given their potential for both positive and negative environmental and societal impacts, the careful study of dams and reservoirs is important to ensuring optimal outcomes.  With tens of thousands of large dams around the globe, an important step in their study has been the mapping and cataloging of existing dams.  In today's lab you will work with data from the United Nations Food and Agricultural Organization (FAO)  _Georeferenced dams database_[^1] to gain insight into the patterns, features, and trends in global dams.

</br>

## Background reading
For some helpful background you should read the _Executive Summary_ section of the following report.  This document will give you a useful overview and context of the issues and will help guide your analysis.  In addition to this document, you may find it helpful to search out other sources to help you make sense of your analysis.  

<br/>

#### Dams and Development: A new framework for decision-making
+ [Read the _Executive Summary_ section](https://stahlm.github.io/ENS_215/Documents/world_commission_on_dams_final_report.pdf)

</br>

#### Other helpful resources
+ [Dams and Reservoirs @ MIT Mission 2017](http://12.000.scripts.mit.edu/mission2017/dams-and-reservoirs/)
+ [High-resolution mapping of the world's reservoirs and dams for sustainable river-flow management](https://stahlm.github.io/ENS_215/Documents/Lehner_et_al_2011.pdf)
+ [Wikipedia page on dams](https://en.wikipedia.org/wiki/Dam) 
+ ["Report Card" on America's Dams](https://infrastructurereportcard.org/cat-item/dams/#:~:text=As%20of%202019%2C%20there%20are,once%2Drural%20dams%20and%20reservoirs.)  
+ [Article on the condition of US dams (includes an interactive map of dams in poor condition)](https://apnews.com/article/ne-state-wire-us-news-ap-top-news-sc-state-wire-dams-f5f09a300d394900a1a88362238dbf77)  


</br>

## Objectives
In the lab that you submit you should discuss your observations/findings related the objectives below.  Do not simply make the figures/tables without providing a discussion.  

### Required

#### 0. Examine the data.  

First you will need to download the data.  The data can be downloaded from our class site using the following code 

```{r eval=FALSE}
library(tidyverse)

dams_data <- read_csv("https://stahlm.github.io/ENS_215/Data/Dams_FAO_SelectCols_LabData.csv")
```

<br/>

You will also need to look at the [readme](https://raw.githubusercontent.com/stahlm/stahlm.github.io/master/ENS_215/Data/readme_dam_data.txt) file associated with the above dataset.  The _readme_ file describes the variables in the dataset.  

Once you've loaded in the data, make sure the data looks ok and familiarize yourself with the different columns.  You can examine/get familiar with the dataset in many ways (e.g. `head()`, `summary()`, `View()`,...).  Remember that `View()` should be run in your CONSOLE not your notebook.  

After looking at the data you may find it helpful to reorder the columns.  You can easily move columns of interest to the front of the dataset using the `select()` function.  You can do this by specifying the columns you want up front and then using the `everything()` function to specify that you would like to put all the remaining columns after the ones you've moved up front.  For instance,  

`select(Dataset, column to move up front, another column to move up front, everything())`  

<br/>

In your submitted lab write-up/discussion, you should provide a short summary/description of the dataset (e.g. number of variables and observations, general content, key variables, period of record,...).

**IMPORTANT NOTE:** some of the variables will have missing data, which is recorded as `NA`.  `NA` values can create issues with some functions (e.g. `mean()`), however these issues can be dealt with by telling the function to ignore observations with `NA` values.  This is done by specifying `na.rm = TRUE` as an input to a function.  For instance `mean(data here, na.rm = TRUE)`.  

<br/>

#### 1. Create a scatter plot showing the relationship between reservoir storage and reservoir area
Do you notice any interesting features?  Comment on your observations.  You may want to try coloring the points by continent to see if there are regional patterns/trends.  

</br>

#### 2. Create a scatter plot showing the relationship between reservoir storage and dam height
Do you notice any interesting features?  Comment on your observations.  Do you observe any outlier or notable points.  You may want to try coloring the points by continent to see if there are regional patterns/trends.

**Hint**: setting your axes to log scale using the `scale_x_log10()` and `scale_y_log10()` can make the plots easier to read/interpret

</br>

#### 3. Calculate height, area, and storage averages by continent and display these results to your notebook.
How do these statistics differ by continent?  Any thoughts on why they may differ?  

**Hint:** Use the functionality of `dplyr` to do this efficiently

</br>

#### 4. Create a box plot to show how the distribution of reservoir storage capacities varies between continents

Once you've made you plot, take and look and note what you observe.  Are the distributions similar or different between continents?

**Hint**: setting your axes to log scale using the `scale_x_log10()` and/or `scale_y_log10()` can make the plots easier to read/interpret  

</br>

### Additional analysis
The task above were intended to get you started.  Once you finish those above tasks you will need to continue with your own analysis.  Below are some additional ideas, however you are more than free (*and encouraged*) to pursue your own ideas.

</br>

#### 1. Create a summary table that has additional info about dams and reservoirs
You could make a table with averages, total, minimums, and maximums for dam height, reservoir area, reservoir storage,...  This table could be for all of the data or broken down by continent (or by country, or by year,...)

</br>

#### 2. Create a plot showing the total number of dams over time 

</br>

#### 3. Select a country or countries of interest and examine the data 

</br>

#### 4. Examine the data on the purposes of the reservoirs (e.g. irrigation, water supply, navigation,...)

<br/> 

## Prepare your final lab report

#### Advice/guidance
Remember that your lab should be a nicely formatted and organized report that includes your code, output, and discussion.  You should have an introduction and conclusion section and you should clearly delineate different sections with headers.  Also remember to cite any sources that your rely/reference.

At this point in the term you should start to think about the organizational logic of your final lab report (i.e. order your analysis sections and discussion in a sensible manner).  You don't need to get bogged down on this point when working in lab, but it is good to consider when you are putting together your final report for submission.      

The "additional analysis" section of your lab is a critical compenent and should be given careful thought and effort.  

It is important to realize that my expectations for each of the graded criteria increase as the term progresses and you gain more skills and are better able to develop your own analyses.  

Make sure you are familiar with the expectations and evaluation criteria presented in the links below:

+ [Evaluation rubric](https://stahlm.github.io/ENS_215/Winter_2022/Syllabus.html#evaluation_rubric)
+ Template for lab and homework assignments: [(html)](https://stahlm.github.io/ENS_215/Homework/Template_Assignments.html) [(Rmd)](https://raw.githubusercontent.com/stahlm/stahlm.github.io/master/ENS_215/Homework/Template_Assignments.Rmd)
+ [Lab report guidelines](https://stahlm.github.io/ENS_215/Labs/Lab_Guidelines.html)

<br/>

#### Submitting the lab
Your lab is due prior to the start of next week’s lab. Once you are finished and satisfied with your work you should Knit it to an `.html` file and submit both your `html` and `Rmd` file to Nexus.

Please make sure that the `.html` file you submit is `.html` and not `nb.html`.

```{r eval = FALSE, echo= FALSE}
[Take a look at this link](https://en.wikipedia.org/wiki/Violin_plot) for more info on violin plots.  

[Also look at this link](http://www.sthda.com/english/wiki/ggplot2-violin-plot-quick-start-guide-r-software-and-data-visualization) for info on how to make a violin plot (the section on **Basic violin plots** is very helpful).  

```


[^1]: Original data source available at: <http://www.fao.org/nr/water/aquastat/dams/index.stm>