## Example of R Markdown

This is an R Markdown document. Typing here makes it appear in the PDF.

# Headings are easy
## Sub-headings are even easier
**Bold** text.

* lists use a star
* like this

1. Numbered lists are obvious
2. Really obvious

# Incorporate R code
The main reason to use markdown is to easily incorporate our analysis from R. 

The number of minutes in a day is `r 60*24`.

This is a table from some random data:
```{r table,echo=FALSE}
library(knitr)
#WorldPhones <- WorldPhones*1000 #REVEAL
kable(WorldPhones)
```

And we can pick out individual numbers from our data, such as the fact that there were $`r WorldPhones["1951","Africa"]`$ phones in Africa in 1951.

Then we can do some calculations on the table in an R code chunk and report some statistics.

```{r calculations,echo=FALSE}
mean_1951 <- mean(WorldPhones["1951",])
mean_SAM <- mean(WorldPhones[,"S.Amer"])

```

The average number of phones across continents in 1951 was $`r format(mean_1951, scientific=FALSE)`$, and the average number of phones in South America from 1951 - 1961  was $`r round(mean_SAM,0)`$.

And a chart:

```{r chart, echo=FALSE}
plot(rownames(WorldPhones),WorldPhones[,"Europe"], type="l", xlab="Year",ylab="Number of Phones, Europe")

```


We can even make interactive charts (only in HTML):
```{r chart2, echo=FALSE,message=FALSE}
library(ggplot2)
library(plotly)
library(reshape2)
WorldPhones_long <- melt(WorldPhones)
colnames(WorldPhones_long) <- c("Year","Continent","Number_Phones")
chart1 <- ggplot(data=WorldPhones_long) + geom_point(aes(x=Year,y=Number_Phones,col=Continent)) + theme_classic()
ggplotly(chart1)

```

If we want to show people what code we used, we can also include the code in our document:

```{r chart2_code, echo=TRUE,eval=FALSE}
library(ggplot2)
library(plotly)
library(reshape2)
WorldPhones_long <- melt(WorldPhones)
colnames(WorldPhones_long) <- c("Year","Continent","Number_Phones")
chart1 <- ggplot(data=WorldPhones_long) + geom_point(aes(x=Year,y=Number_Phones,col=Continent)) + theme_classic()
ggplotly(chart1)

```

Try knitting this .Rmd file to a pdf, html and word document.