'data.frame': 200 obs. of 7 variables:
$ Status : Factor w/ 2 levels "counterfeit",..: 2 2 2 2 2 2 2 2 2 2 ...
$ Length : num 215 215 215 215 215 ...
$ Left : num 131 130 130 130 130 ...
$ Right : num 131 130 130 130 130 ...
$ Bottom : num 9 8.1 8.7 7.5 10.4 9 7.9 7.2 8.2 9.2 ...
$ Top : num 9.7 9.5 9.6 10.4 7.7 10.1 9.6 10.7 11 10 ...
$ Diagonal: num 141 142 142 142 142 ...
Stat 1080 Lab: Data Visualization
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.
Understanding The Data
The following chunks use object-inspection functions to get a sense of the data. Answer the questions below.
Status Length Left Right Bottom
counterfeit:100 Min. :214 Min. :129 Min. :129 Min. : 7.20
genuine :100 1st Qu.:215 1st Qu.:130 1st Qu.:130 1st Qu.: 8.20
Median :215 Median :130 Median :130 Median : 9.10
Mean :215 Mean :130 Mean :130 Mean : 9.42
3rd Qu.:215 3rd Qu.:130 3rd Qu.:130 3rd Qu.:10.60
Max. :216 Max. :131 Max. :131 Max. :12.70
Top Diagonal
Min. : 7.7 Min. :138
1st Qu.:10.1 1st Qu.:140
Median :10.6 Median :140
Mean :10.7 Mean :140
3rd Qu.:11.2 3rd Qu.:142
Max. :12.3 Max. :142
Hint: You can read the documentation about the dataset by typing ?banknote in the console. This will provide additional context in the Help window.
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
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:
- What type of plot is this?
- Which variables are mapped to
x,y, andfill? - What is the main finding from the plot?
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:
- What type of plot is this?
- Which variables are mapped to
x,y, andfill? - What is the main finding from the plot?
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:
- What type of plot is this?
- Which variables are mapped to
x,y, andfill? - What is the main finding from the plot?
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.
Use the penguins data, which is loaded in the chunk below.
species island bill_len bill_dep flipper_len body_mass sex year
1 Adelie Torgersen 39.1 18.7 181 3750 male 2007
2 Adelie Torgersen 39.5 17.4 186 3800 female 2007
3 Adelie Torgersen 40.3 18.0 195 3250 female 2007
4 Adelie Torgersen NA NA NA NA <NA> 2007
5 Adelie Torgersen 36.7 19.3 193 3450 female 2007
6 Adelie Torgersen 39.3 20.6 190 3650 male 2007
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:
- What type of plot is this?
- Which variables are mapped to which aesthetics?
- What is the main finding from the plot?
Note that I fully expect your answer to this to be different, as I do not want you going to find the scatterpie package (it’s actually pretty badly written) and using it. You’re welcome to use other packages in the ggplot2 universe, but it is 100% possible to create a horrible chart with just base ggplot2.
In this plot, I have used pie charts (which are less easily read than bar charts, because angles are less accurately perceived than lengths) in an inappropriate way, by plotting them as points in a line chart of average body mass by year. In addition, I have used a red-green-yellow fill mapping for sex, with yellow corresponding to unknown, red corresponding to male (leveraging gendered color schemes that aren’t universal), and green corresponding to female. In addition, I have mapped the radius of the pie chart to the number of data points, but this results in the area of the circle being mapped to the square of the number of data points, leading to inaccurate perception of the magnitude of data. I have also extended the range of the y-axis inappropriately below zero, which would correspond to a negative-mass penguin, which is (hopefully) impossible, as it is a violation of the laws of physics. I have adjusted the facet titles to have a black background with very dark grey titles, which does not have sufficient contrast to be readable. For similarly inexplicable reasons, I’ve changed the grid lines to be a color called “lavenderblush”, which has insufficient contrast with the background, and I’ve made the lines dotted to make them even harder to see.