---
title: "Example"
author: "Andrew Heiss"
date: "9/19/2017"
output:
  html_document:
    highlight: pygments
    toc: yes
  pdf_document:
    toc: yes
---

## Cool headings

asdkjlfal;cx

lm,j;kljl;zcx

- asdf
- *thing*
- thing2 

First, we load the packages:

```{r load-packages, message=FALSE, warning=FALSE}
library(tidyverse)
library(readxl)
library(scales)
```

Now we load the data:

```{r load-data, message=FALSE, warning=FALSE}
cr <- read_excel("data/ComicRelief_360Giving_International.xlsx")

# glimpse(cr)
```

Summary stats!!! 

```{r summary-stats}
x <- mean(cr$`Amount Awarded`)
median(cr$`Amount Awarded`)
var(cr$`Amount Awarded`)
sd(cr$`Amount Awarded`)

sqrt(var(cr$`Amount Awarded`))

summary(cr$`Amount Awarded`)
```

The average amount donated is £`r comma(x)`

# Graphs

## Histograms

When there are 50 bins, something.

```{r hist1}
library(ggthemes)
ggplot(cr, aes(x = `Amount Awarded`)) +
  geom_histogram(bins = 50) +
  labs(x = "MONEY", y = "Count", title = "This is a cool plot",
       subtitle = "Something", caption = "Source: my head") + 
  theme_fivethirtyeight()
```

But when there are 2, something else.

```{r hist2, fig.height=2, fig.width=7}
ggplot(cr, aes(x = `Amount Awarded`)) +
  geom_histogram(bins = 3) +
  labs(x = "MONEY", y = "Count", title = "This is a cool plot",
       subtitle = "Something", caption = "Source: my head") + 
  theme_fivethirtyeight()
```

## Density plots

```{r density1}
ggplot(cr, aes(x = `Amount Awarded`)) +
  geom_density(fill = "red", color = NA) + 
  geom_vline(xintercept = mean(cr$`Amount Awarded`), 
             linetype="dashed", size = 1, color = "darkred") + 
  geom_vline(xintercept = median(cr$`Amount Awarded`), 
             linetype="dotted", size = 1, color = "black") + 
  theme_minimal()
```

cr_kt <- cr %>%
  filter(`Beneficiary Location:0:Name` %in% c("Kenya", "Tanzania")) %>%
  rename(country = `Beneficiary Location:0:Name`)
  
```{r change-data}
cr_kt <- cr %>%
  filter(`Beneficiary Location:0:Name` %in% c("Kenya", "Tanzania")) %>%
  rename(country = `Beneficiary Location:0:Name`)

ggplot(cr_kt, aes(x = `Amount Awarded`, fill = country)) +
  geom_density(alpha = 0.5)
```

