---
title: 'Stat 480 - Homework #8'
date: "3/12/2020"
output: html_document
---

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

<br/>

## The Joy of Painting with Bob Ross

![](https://static01.nyt.com/images/2019/07/13/arts/13video/bob-ross-cover-videoSixteenByNineJumbo1600-v5.png)


<br/>

### Submission Details

**Due date**: the homework is due before class on Thursday. 

**Submission process**: submit both the R Markdown file and the corresponding html file on canvas. Please submit both the `.Rmd` and the `.html` files separately and do not zip the two files together.

<br/>

### Questions

1. Download the RMarkdown file with these homework instructions to use as a template for your work. Make sure to replace "Your Name" in the YAML with your name.

```{r}
# load necessary libraries
library(dplyr)
library(tidyr)
library(ggplot2)
library(forcats)
library(readr)
```


2. The data this week comes from [fivethiryeight](https://github.com/fivethirtyeight/data). The data set includes information on the 403 episodes of "The Joy of Painting". The accompanying article is published [here](https://fivethirtyeight.com/features/a-statistical-analysis-of-the-work-of-bob-ross/).  

```{r }
# read in the data
bob_ross <- read_csv('https://raw.githubusercontent.com/Stat480-at-ISU/Stat480-at-ISU.github.io/master/homework/data/bob-ross.csv')
```

3. Variables `alizarin_crimson` through `burnt_umber` correspond to the binary presence (0 or 1) of that color in the painting. Gather all of these variables and create a long form of the data, introducing two new variables called `color` and `presence`. Save the result in a data frame called `bob_ross_colors`.

```{r}
bob_ross_colors <- bob_ross %>%
  pivot_longer(alizarin_crimson:burnt_umber, names_to = "color", values_to = "presence")
```


4. Does Bob Ross have a favorite color to paint with? Use the data `bob_ross_colors` as your starting point and for each color calculate the number of times that color was used throughout the series. After using this number to reorder the levels of the variable `color`, create a bar chart using the code below as your starting point and add in the necessary aesthetic mappings within `ggplot(aes( ))`. Describe and summarise the chart.

```
question4_data %>%
  ggplot(aes( )) + 
  geom_bar(show.legend = FALSE) + 
  coord_flip() + 
  theme_minimal() +
  labs(y = "Number of paintings",
       x = "", 
       title = "Frequency of colors in Bob Ross Paintings") +
  scale_fill_manual(values = c("#CD5C5C", "#8A3324", "#2C6436", "#3C67A7", "#643914", "#E7BD2F", "#546F1F", "#C36A4A", "#346BB1", "#B58A30", "#F8ED5F", "#372518", "#973B29")) 
```


```{r}
bob_ross_colors %>%
  group_by(color) %>% 
  summarise(n = sum(presence)) %>% 
  mutate(color = fct_reorder(color, n)) %>%
  ggplot(aes(x = color, weight = n, fill = color)) + 
  geom_bar(show.legend = FALSE) + 
  coord_flip() + 
  theme_minimal() +
  labs(y = "Number of paintings",
       x = "", 
       title = "Frequency of colors in Bob Ross Paintings") +
  scale_fill_manual(values = c("#CD5C5C", "#8A3324", "#2C6436", "#3C67A7", "#643914", "#E7BD2F", "#546F1F", "#C36A4A", "#346BB1", "#B58A30", "#F8ED5F", "#372518", "#973B29"))
```

We see that Bob Ross liked and utilized dark red/brown colors as crimson and brown are his top two favorite colors. They each both had over 350 appearances. Additionally, his fourth favorite color, ochre, is a type of brown as well. These results make sense as Bob Ross was known for painting nature landscapes. Brown is a common color in nature, whether it be soil or wood on a tree. Overall, the graph shows which colors Bob Ross used the most in his paintings.


5. For this question use the original data again. Variables `aurora_borealis` through `winter` correspond to the binary presence (0 or 1) of that element in the painting. Use `pivot_longer()` as shown in class to transform the data into a tidier format with new variables `element` and `presence`. Save the result in a data frame called `bob_ross_elements`.

```{r}
bob_ross_elements <- bob_ross %>%
  pivot_longer(aurora_borealis:winter, names_to = "element", values_to = "presence") 
```


6. What are the most frequent elements in his paintings?  Use the data `bob_ross_elements` as your starting point and for each element calculate the number of times that element was included. Then use this number to reorder the levels of `element`. Exclude elements that were featured in fewer than 50 paintings and create a bar chart. Use the code below as your starting point and add in the necessary aesthetic mappings within `ggplot(aes( ))`. Describe and summarize the chart.

```
question6_data %>%
  ggplot(aes( )) + 
  geom_bar(fill = "seagreen") + 
  coord_flip() + 
  theme_minimal() +
  labs(y = "Number of paintings",
       x = "", 
       title = "What were most common features in Bob Ross paintings?",
       subtitle = "Paintings by the numbers")
```

```{r}
bob_ross_elements %>% 
  group_by(element) %>% 
  summarise(n = sum(presence)) %>% 
  mutate(element = fct_reorder(element, n)) %>%
  filter(n > 50) %>% 
  ggplot(aes(x = element, weight = n)) + 
  geom_bar(fill = "seagreen") + 
  coord_flip() + 
  theme_minimal() +
  labs(y = "Number of paintings",
       x = "", 
       title = "What were most common features in Bob Ross paintings?",
       subtitle = "Paintings by the numbers")
```

We see that Bob Ross really liked to paint trees. The most common element in his paintings (over 350 occurrences) is a tree. The second most common element in his paintings is having multiple trees, this occurs over 300 times. Additionally, the third and fourth most common elements are deciduous and conifer, which are again, both types of trees! This plot shows that if you were handed an original Bob Ross, it would likely have a tree on it! Additionally, other elements featured in his paintings are included in this chart as well. Examples of other elements are rivers, lakes, mountains, and clouds. These elements were all in less than 200 paintings. One noticeably missing element is humans. Ross apparently preferred painting natural landscapes without humans interfering in the beauty of nature.


7. Did the content of the paintings change over time? We will attempt to answer this question by looking at elements that appeared in more than 90 paintings and their trends over the seasons.  Use the data `bob_ross_elements` as your starting point and for each season and element, calculate the number of times an element was included. Exclude elements that were included in less than 90 paintings total. Create a line plot showing number of times an element was included for each season with season on the x-axis and facet by element. Use the code below as your starting point and add in the necessary aesthetic mappings within `ggplot(aes( ))` and add in the faceting. Describe and summarize the chart.

```
question7_data %>%
  ggplot(aes( )) + 
  geom_line(color = "deepskyblue") + 
  # add faceting here
  labs(y = "Number of paintings with element",
       title = "The content of Bob Ross paintings over time",
       subtitle = "Dashed line is number of episodes in the season") + 
  geom_hline(yintercept = 13, lty = 2, color = "grey70") + 
  theme_minimal() + 
  expand_limits(y = 0) 
  ```


```{r}
bob_ross_elements %>%
  group_by(season, element) %>% 
  summarise(n_paintings = sum(presence)) %>% 
  group_by(element) %>% 
  mutate(n_paintings_total = sum(n_paintings)) %>%
  filter(n_paintings_total > 90) %>%
  ggplot(aes(x = season, y = n_paintings)) + 
  geom_line(color = "deepskyblue") + 
  facet_wrap(~ element) + 
  labs(y = "Number of paintings with element",
       title = "The content of Bob Ross paintings over time",
       subtitle = "Dashed line is number of episodes in the season") + 
  geom_hline(yintercept = 13, lty = 2, color = "grey70") + 
  theme_minimal() + 
  expand_limits(y = 0) 

```


We see that over time, Bob Ross changed how often the elements of bushes, clouds, conifer, deciduous, grass, lake, mountain, mountains, river, snowy_mountain, tree, and trees all appeared in his paintings. For example, we see that Bob Ross initially increased the amount of paintings that featured clouds during the early seasons, and then began to decrease the number of paintings that had clouds starting around season 10. Ultimately, the number of paintings with clouds returned to its original amount by the end of the show. For the element river, we see a spike in the number of paintings that featured this element around seasons 6, 12, and 22; however, the number of paintings containing a river ends up close to its original starting place by season 30. Similar analysis can be done for the remaining elements to see how often they appeared in Bob Ross’s paintings over the course of the show.

