R visualization workshop
Welcome
I Week I
Overview Week 1
1 R, Rstudio, and packages
2 ggplot – a quick overview
3 ggplot – some theory
4 ggplot – the geoms
5 Distribution of a single variable
6 Reproducible workflows
7 Class assignment
II Week 2
Overview Week 2
8 Comparing distributions
9 Using extension packages
10 Class assignment 2
III Week 3
Overview Week 3
11 Comparing group statistics
12 Transform data
13 Revisiting earlier graphs
14 Class assignment 3
IV Week 4
Overview Week 4
15 Visualizing two continuous variables
16 Revisiting earlier graphs 2
17 Figure size
18 Class assignment 4
V Week 5
Overview Week 5
19 Visualizing two discrete variables
20 Annotate graphs
21 Combining plots
22 Class assignment 5
VI Assignments
Assignment 1
Assignment 2
Assignment 3
Assignment 4
Assignment 5
◦ Preparation
◦ Visualization
◦ Submit your PDF-file online
VII Other useful stuff
Themes
Titles, text and legends
Scales, Axes & Coordinate systems
Colours
Facets
The legend
Saving plots
Importing data
Help!?
References
Published with bookdown
Assignment 5
Preparation
Download this Rmarkdown file, fill in your name and student number, and complete your assignment in the Rmarkdown file. “knit” your text and code into a pdf-file, and upload this pdf-file on Nestor before the next lecture. Make sure that your pdf-output looks correct.
Visualization
The dataset that we’ll use comes from one of the articles of the awesome website fivethirtyeight. A beautiful feature of this website is that all data underlying the articles are open for readers to verify: https://github.com/fivethirtyeight/data. Here, we’ll focus on the article What Do Men Think It Means To Be A Man?. Read the article and look closely at the first visualisation. The assignment is to try and recreate that graph as closely as possible.
Packages & Data
The below code will download the survey-data and select two columns from the survey:
• q0005: this variable gives the answers to the question: “Do you think that society puts pressure on men in a way that is unhealthy or bad for them?”. Possible answers are: yes / no / no answer
• age3: this variable stores the age of the respondent in three categories, 18 – 34 / 35 – 64 / 65 and up
library(ggplot2)
library(tidyverse)
data <- read.csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/masculinity-survey/raw-responses.csv",
header = TRUE) %>% select(q0005, age3)
table(data$q0005)
##
## No No answer Yes
## 647 13 955
table(data$age3)
##
## 18 – 34 35 – 64 65 and up
## 133 855 627
Your task
• Try to recreate the first graph in the article as closely as possible.
• You will probably need the package patchwork or cowplot to combine graphs.
• You can make use of the package ggthemes but you don’t have to.
• Explain in no more than 250 words what the graph is showing, and what unique insights it delivers. Also reflect on what it fails to show or what you would have liked to include in the graph but was not able to.
Submit your PDF-file online
When you are done with your assignment, try clicking the “Knit”-button in Rstudio so that your code will be knitted into a pdf-file. Submit this file on Nestor.
If you see an error appear, try to fix the error and try again. If you can’t get the “knitting” to work, then you can copy your code, text, and graphs into a word-file and submit it on Nestor.