Literate programming

Getting started

Markdown

Explore patterns in population dynamics at Portal.

## Required Libraries

R chunks

```{r}
```
```{r}
library(dplyr)
```
```{r, message=FALSE}
library(dplyr)
```
```{r, message=FALSE}
library(dplyr)
library(ggplot2)
```
```{r, message=FALSE, warning=FALSE}
library(dplyr)
library(ggplot2)
```

Analysis Report Example

## Data

Data is from the [Portal project teaching database](http://figshare.com/articles/Portal_Project_Teaching_Database/1314459) 
published on Figshare. We need the surveys table for our analysis:

```{r, cache=TRUE}
download.file("https://ndownloader.figshare.com/files/2292172", 
              "surveys.csv")
data <- read.csv("surveys.csv")
```
## Analyze population time-series

Get the time-series of counts for all species.
          
```{r}
time_series <-
  data %>%
  group_by(species_id, year) %>%
  summarize(count = n()) %>%
  na.omit()

head(time_series)
```
## Plot the time-series.

```{r, message=FALSE, echo=FALSE, cache=TRUE}
ggplot(time_series, aes(x = year, y = count)) +
  geom_point() +
  geom_line() +
  facet_wrap(~species_id) +
  scale_x_continuous(breaks = pretty_breaks(n=2))
```

## A simple model

```{r, echo=FALSE}
model <- data %>% group_by(year) %>% 
  summarize(count = n()) %>% 
  lm(count ~ year, data = .)

results <- anova(model)
```
We found a marginally significant linear relationship between the
total count and year (p = `r round(results[["Pr(>F)"]][1], 3)`; see
Table 1 for more details)

```{r, echo=FALSE}
knitr::kable(results, caption = "Table 1")
```

R Presentations

Untitled
========================================================
author: 
date: 
autosize: true

First Slide
========================================================

For more details on authoring R presentations please visit <https://support.rstudio.com/hc/en-us/articles/200486468>.

- Bullet 1
- Bullet 2
- Bullet 3

Slide With Code
========================================================

```{r}
summary(cars)
```