---
title: "Stat 1080 Lab: Data Visualization"
author: Your Name Here
execute:
  error: true
  echo: true
format:
  html:
    embed-resources: true
---

You can find the visual solutions for this assignment [here](srvanderplas.github.io/stat1080/lab/21-effective-data-vis-visual-sol.html).

## Swiss Banknotes

The R package `mclust` contains a data set called `banknote`, consisting of (physical) measurements on 200 Swiss bank notes, 100 of which are genuine, while the other half is counterfeit. 

The following code will check to see if `mclust` is installed, and if it is not, it will install the package before loading the `banknote` data. 

```{r}
#| echo: false
#| include: false
#| label: setup
if (!"mclust" %in% installed.packages()) {
  install.packages("mclust")
}
library(mclust)
data("banknote")
library(ggplot2)

options(digits = 3)
set_theme(theme_bw())
```


### Understanding The Data

The following chunks use object-inspection functions to get a sense of the data. 
Answer the questions below. 

```{r}
str(banknote) # Structure of the dataset
```

```{r}
summary(banknote) # 6-number summaries of numeric vars, frequency distributions for categorical vars
```

Hint: You can read the documentation about the dataset by typing `?banknote` in the console. This will provide additional context in the Help window. 


<!-- Understanding The Data answers here -->

How many observations are there which are counterfeit? How many are genuine?

> *Replace this with your answer*

What units are the measurements in?

> *Replace this with your answer*

Which measurements have the most variability, measured by the range of observations?

> *Replace this with your answer*

<!-- End Understanding The Data answers -->

### Examining Status

Draw a barchart of Status. 
In addition to showing status on the x or y axis (your choice), map status to the fill color of the bars. 
(Yes, this plot is a bit simplistic, but what does it show? Does it confirm your answer in the previous question?)
In the chunk below, edit the `fig-cap` chunk option (replacing "Your description goes here" with your answer) to provide a meaningful 3-sentence caption that addresses the following:

1. What type of plot is this?
2. Which variables are mapped to `x`, `y`, and `fill`?
3. What is the main finding from the plot?

<!-- Examining Status answer here -->

```{r}
#| fig-width: 5
#| fig-height: 5
#| out-width: 50%
#| fig-cap: "Your description goes here"

# Uncomment the lines below. Compare your solution to the visual solutions posted for this lab.
## ggplot(...) + 
##   geom_bar(...) + 
##   labs(...)
```

<!-- End Examining Status answer -->

### Detecting Counterfeits

Draw a histogram of one of the variables in the dataset that shows a distinction between genuine and counterfeit banknotes. Use fill color to show this difference. 
Choose the binwidth such that there are no gaps in the middle range of the histogram.
In the chunk below, edit the `fig-cap` chunk option (replacing "Your description goes here" with your answer) to provide a meaningful 3-sentence caption that addresses the following:

1. What type of plot is this?
2. Which variables are mapped to `x`, `y`, and `fill`?
3. What is the main finding from the plot?

<!-- Detecting Counterfeits answer here -->

```{r}
#| fig-width: 6
#| fig-height: 4
#| fig-cap: "Your description goes here"

# Uncomment the lines below. Compare your solution to the visual solutions posted for this lab.
## ggplot(...) + 
##   geom_histogram(...) + 
##   labs(...)
```

<!-- End Detecting Counterfeits answer -->

### Detecting Counterfeits, Part II

The code below draws a scatterplot of two (continuous) measurements.
Modify the code to color points by whether the banknote is genuine or fake. 
What can you conclude from the plot about how these two measurements can be used to detect counterfeit bills?

In the chunk below, edit the `fig-cap` chunk option (replacing "Your description goes here" with your answer) to provide a meaningful 3-sentence caption that addresses the following:

1. What type of plot is this?
2. Which variables are mapped to `x`, `y`, and `fill`?
3. What is the main finding from the plot?


<!-- Detecting Counterfeits II answer here -->

```{r}
#| fig-width: 7
#| fig-height: 5
#| fig-cap: "Your description goes here"

### Uncomment the lines below. Compare your solution to the visual solutions posted for this lab.
## ggplot(data = banknote, 
##        aes(x = Diagonal, 
##            y = Bottom, 
##            ...,
##            )) +
##   geom_jitter(alpha = .6) +
#### Uncomment this line if you need extra help with what the plot shows
##   # geom_abline(slope = 1.1, intercept = 7-138.5*1.1, linetype = "dotted") + 
##   labs(title = "Swiss Banknotes", 
##        subtitle = "Genuine and counterfeit bill dimensions", 
##        x = "Diagonal length (mm)", 
##        y = "Bottom margin width (mm)",
##        color = "Bill Status")
```

<!-- End Detecting Counterfeits II answer -->

## Take everything you know, and use it for evil

We spent some time discussing principles of good graphics in class, but we spent less time showing you all of the different ways you could customize graphics in `ggplot2`. Here, I want you to create the *ugliest* graphs (e.g. least useful, violating the most principles of good graphics) you can, and then **explain why**, exactly, the graphs are ugly, and which principles of good graphics you've intentionally violated. Note that it is not enough for your chart to be aesthetically displeasing - you should strive to make the chart functionally ineffective by violating principles of good graphics.

Of course, ugliness is subjective. 
One goal of this assignment is for you to explore the different ways you can customize the finer details of a plot: color schemes, theme elements, shape mappings, and so on. 

Requirements:
- Your finished masterpiece must have **appropriate axis labels and a title** (after all, even ugly plots need to be correctly labeled!). 
- Your ugliness **should not depend solely on color choices** - there are many other ways to make things ugly!

You are free to add additional variables and layers, modify the aesthetics used, and leverage other packages. 
If you use packages I haven't used in the book, please provide (commented out) installation code in your code chunks, modeled on the code which installs `mclust` at the start of this assignment.

[If you need inspiration, look here.](https://web.archive.org/web/20220730230323/https://www.allisonhorst.com/post/do-your-worst/)

Use the `penguins` data, which is loaded in the chunk below.

```{r}
data(penguins)
head(penguins)
# ?penguins # Uncomment and run this to pull up the penguins help file
```

Create the ugliest graph you can manage. 
You can pick which variables to plot, what type of chart to make, and what aesthetic mappings to use.

When you are finished, edit the `fig-cap` chunk option (replacing "Your description goes here" with your answer) to provide a meaningful 3-sentence caption that addresses the following:

1. What type of plot is this?
2. Which variables are mapped to which aesthetics?
3. What is the main finding from the plot?

<!-- Evil answer here -->

```{r}
#| fig-width: 7
#| fig-height: 5
#| fig-cap: "Your description goes here"

```

*Delete this line and explain why your graph is ugly - what principles of good graphics have you violated?*

<!-- Evil answer -->




## Useful References

- [Customizing ggplot2 graphics](http://r-statistics.co/Complete-Ggplot2-Tutorial-Part2-Customizing-Theme-With-R-Code.html)

- [A group-created slideshow of awful graphics](https://docs.google.com/presentation/d/1ixRsGI8BWgT2zA5AbB61eMLUbJgObvBCZt-OnZDzvX4/edit?usp=sharing)


