---
title: Create a simple, functioning script
week: 1 
subtitle: Write a script that reads in data, calculates a statistic, and makes a plot.
type: Case Study
reading:
  - R4DS [Chapter 1](http://r4ds.had.co.nz/introduction.html)
  - R4DS [Chapter 2](http://r4ds.had.co.nz/explore-intro.html)
  - Datacamp's [_How to Make a Histogram with Basic R_](https://www.datacamp.com/community/tutorials/make-histogram-basic-r)
  - Datacamp's [_How to Make a Histogram with ggplot_](https://www.datacamp.com/community/tutorials/make-histogram-ggplot2)
tasks:
  - Create a new R script in RStudio
  - Load the iris dataset with `data(iris)`
  - Calculate the mean of the `Petal.Length` field
  - Plot the distribution of the `Petal.Length` column as a histogram
  - Save the script
  - Click 'Source' in RStudio to run it from beginning to end
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
library(kableExtra)
source("functions.R")
```
# Reading
```{r reading,results='asis',echo=F}
md_bullet(rmarkdown::metadata$reading)
```

# Background
You are working on a new project and your colleague has asked you to calculate the mean Petal Length in the dataset she collected in the field.  

It looks like this:

```{r, echo=F}
data(iris)
kable(iris) %>%
  kable_styling() %>%
  scroll_box(width = "100%", height = "200px")
```

For the histogram, you can either use the basic `hist()` function (easier but less powerful) or try to use the `geom_hist()` function in ggplot (more complicated but much more powerful).  See the reading list for hints on these two functions.

When you complete this task, you will have done some 'reproducible research' resulting in a script that calculates a statistic and makes a graph.  In future lessons we'll cover how to save the graphic to your hardrive (if you are curious, check out the examples in `?png`)

# Tasks
```{r tasks,results='asis',echo=F}
md_bullet(rmarkdown::metadata$tasks)
```
