---
title: "RMarkdown Example"
author: "kvlinden"
date: "Spring, 2022"
output: 
  html_document
---

```{r include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```


## RMarkdown

RMarkdown is a simple formatting syntax for authoring documents that interleave text, images, and code. All assignments will be formatted using RMarkdown.

Distinguish between the RMarkdown *source* file and the HTML *output* file. Press the **Knit** button in RStudio to generate the latter from the former. 

This document demos the GapMinder example included in the class slides.


## Interleaving Graphics and Code

RMarkdown documents can interleave text markup, images, programming code, and code output. 

### Images

![Here&rsquo;s Calvin&rsquo;s Logo](https://calvin.edu/dotAsset/c223e958-2bec-4c04-8949-644591626f1c.png){width="300px"}

### Code

This code loads the libraries required for the demo.

```{r}
library(gapminder)
library(dplyr)
library(ggplot2)
```

### Code Output

This code displays the raw data in the gapminder dataset.

```{r}
gapminder
```

### Plots

You can also embed plots. For example, here is the plot inspired by Rosling&rsquo;s GapMinder animation.

```{r echo = FALSE}
gapminder %>% 
  filter(year == 2007) %>%
  ggplot() +
  aes(x = gdpPercap, 
      y = lifeExp, 
      color = continent, 
      size = pop
      ) + 
  geom_point() + 
  coord_cartesian(ylim = c(40, 85)) + 
  scale_x_continuous(breaks = c(400, 4000, 40000), trans = "log10") + 
  labs(x = "GDP per Capita", 
       y = "Life Expectancy (years)", 
       color = "Continent", 
       size = "Population") + 
  scale_size_area(labels = function(breaks) 
    format(breaks, big.mark = ",", scientific = FALSE)) + 
  theme_bw() +
  annotation_logticks(sides = "b")
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
