Introductions
Get to know the others at your table. Share your names, preferred pronouns, and anything else that is important to you.
A taste of data visualization in R
Throughout the semester we’ll be using the statistical software R to analyze data. We’ll take a first look at R code today in the following activity.
Board games are a favorite hobby of your instructor, and to her delight, there is a dataset containing information about many different board games and their ratings from the website BoardGameGeek.com!
You will work through exploring this dataset in pairs, and the instructor will be circling around to help. For some phases of this exploration, you will need to have this page open to access the data description.
This code may seem foreign at first, but over the semester you will have a lot of practice, and you’ll be able to write code like this by yourself at the end! Today, focus on getting a feel for what the code looks like and its potential for helping us gain insight.
Warm-up
The data are stored in an object (a container) called games
. Let’s get a quick feel for this data.
- How many variables are present? Which are quantitative? Which are categorical?
- How many cases, or units of observation, do we have?
- How are the variables named / labeled?
eyJsYW5ndWFnZSI6InIiLCJwcmVfZXhlcmNpc2VfY29kZSI6ImxpYnJhcnkoZ2dwbG90MilcbmxpYnJhcnkoZHBseXIpXG5saWJyYXJ5KHJlYWRyKVxuZ2FtZXMgPC0gcmVhZHI6OnJlYWRfY3N2KFwiaHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3Jmb3JkYXRhc2NpZW5jZS90aWR5dHVlc2RheS9tYXN0ZXIvZGF0YS8yMDE5LzIwMTktMDMtMTIvYm9hcmRfZ2FtZXMuY3N2XCIpIiwic2FtcGxlIjoiIyBMb29rIGF0IHRoZSBmaXJzdCA2IHJvd3NcbmhlYWQoZ2FtZXMpXG5cbiMgSG93IG1hbnkgcm93cyBhbmQgY29sdW1ucyBkb2VzIHRoZSBkYXRhIGhhdmU/XG4jIFdoYXQgYXJlIGl0cyBkaW1lbnNpb25zP1xuZGltKGdhbWVzKSJ9
Phase 1
- Use the code below to construct a visualization (a histogram) of average ratings for the games.
- What do you notice? What information can you gain from this plot?
- What do you think
binwidth = 2
does? Try setting a different value for binwidth
to make a plot that looks better to you.
eyJsYW5ndWFnZSI6InIiLCJwcmVfZXhlcmNpc2VfY29kZSI6ImxpYnJhcnkoZ2dwbG90MilcbmxpYnJhcnkoZHBseXIpXG5saWJyYXJ5KHJlYWRyKVxuZ2FtZXMgPC0gcmVhZHI6OnJlYWRfY3N2KFwiaHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3Jmb3JkYXRhc2NpZW5jZS90aWR5dHVlc2RheS9tYXN0ZXIvZGF0YS8yMDE5LzIwMTktMDMtMTIvYm9hcmRfZ2FtZXMuY3N2XCIpIiwic2FtcGxlIjoiIyBDcmVhdGUgYSBwbG90IG9mIGF2ZXJhZ2UgcmF0aW5ncyAoaGlzdG9ncmFtKVxuZ2dwbG90KGdhbWVzLCBhZXMoeCA9IGF2ZXJhZ2VfcmF0aW5nKSkgK1xuICAgIGdlb21faGlzdG9ncmFtKGJpbndpZHRoID0gMikifQ==
Phase 2
- Another way to visualize average ratings is shown below. Use the code below to construct a density plot of average ratings.
- Do you like this plot or the previous one better? Why?
eyJsYW5ndWFnZSI6InIiLCJwcmVfZXhlcmNpc2VfY29kZSI6ImxpYnJhcnkoZ2dwbG90MilcbmxpYnJhcnkoZHBseXIpXG5saWJyYXJ5KHJlYWRyKVxuZ2FtZXMgPC0gcmVhZHI6OnJlYWRfY3N2KFwiaHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3Jmb3JkYXRhc2NpZW5jZS90aWR5dHVlc2RheS9tYXN0ZXIvZGF0YS8yMDE5LzIwMTktMDMtMTIvYm9hcmRfZ2FtZXMuY3N2XCIpIiwic2FtcGxlIjoiIyBDcmVhdGUgYSBwbG90IG9mIGF2ZXJhZ2UgcmF0aW5ncyAoZGVuc2l0eSBwbG90KVxuZ2dwbG90KGdhbWVzLCBhZXMoeCA9IGF2ZXJhZ2VfcmF0aW5nKSkgK1xuICAgIGdlb21fZGVuc2l0eSgpIn0=
Phase 3
- Using code similar to either of the two above examples in Phases 1 and 2, what other variables might you visualize in a similar way? Try the code here.
- Make note of any interesting findings.
eyJsYW5ndWFnZSI6InIiLCJwcmVfZXhlcmNpc2VfY29kZSI6ImxpYnJhcnkoZ2dwbG90MilcbmxpYnJhcnkoZHBseXIpXG5saWJyYXJ5KHJlYWRyKVxuZ2FtZXMgPC0gcmVhZHI6OnJlYWRfY3N2KFwiaHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3Jmb3JkYXRhc2NpZW5jZS90aWR5dHVlc2RheS9tYXN0ZXIvZGF0YS8yMDE5LzIwMTktMDMtMTIvYm9hcmRfZ2FtZXMuY3N2XCIpIiwic2FtcGxlIjoiIyBWaXN1YWxpemUgc29tZSBvdGhlciB2YXJpYWJsZXMifQ==
Phase 4
- Using the code below, construct a visualization of average ratings broken down by minimum number of players.
- What do you notice? What is surprising? What is not surprising?
eyJsYW5ndWFnZSI6InIiLCJwcmVfZXhlcmNpc2VfY29kZSI6ImxpYnJhcnkoZ2dwbG90MilcbmxpYnJhcnkoZHBseXIpXG5saWJyYXJ5KHJlYWRyKVxuZ2FtZXMgPC0gcmVhZHI6OnJlYWRfY3N2KFwiaHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3Jmb3JkYXRhc2NpZW5jZS90aWR5dHVlc2RheS9tYXN0ZXIvZGF0YS8yMDE5LzIwMTktMDMtMTIvYm9hcmRfZ2FtZXMuY3N2XCIpIiwic2FtcGxlIjoiIyBWaXN1YWxpemUgYXZlcmFnZSByYXRpbmdzIGZvciBkaWZmZXJlbnQgbnVtYmVycyBvZiBtaW4uIHBsYXllcnNcbmdncGxvdChnYW1lcywgYWVzKHggPSBhdmVyYWdlX3JhdGluZykpICtcbiAgICBnZW9tX2hpc3RvZ3JhbSgpICtcbiAgICBmYWNldF93cmFwKH4gbWluX3BsYXllcnMpIn0=
Phase 5
- Using the code below, construct two alternate visualizations of average ratings broken down by minimum number of players. These plots use color instead of panels and also only keep games for which the minimum number of players ranges from 1 to 4.
- Which of the three visualizations do you like best? Why?
eyJsYW5ndWFnZSI6InIiLCJwcmVfZXhlcmNpc2VfY29kZSI6ImxpYnJhcnkoZ2dwbG90MilcbmxpYnJhcnkoZHBseXIpXG5saWJyYXJ5KHJlYWRyKVxuZ2FtZXMgPC0gcmVhZHI6OnJlYWRfY3N2KFwiaHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3Jmb3JkYXRhc2NpZW5jZS90aWR5dHVlc2RheS9tYXN0ZXIvZGF0YS8yMDE5LzIwMTktMDMtMTIvYm9hcmRfZ2FtZXMuY3N2XCIpIiwic2FtcGxlIjoiIyBTdWJzZXQgdGhlIGRhdGEgdG8gb25seSBrZWVwIGdhbWVzIHdoZXJlIG1pbl9wbGF5ZXJzIGlzIGZyb20gMSB0byA0XG5nYW1lc19zdWIgPC0gZHBseXI6OmZpbHRlcihnYW1lcywgbWluX3BsYXllcnMgPj0gMSwgbWluX3BsYXllcnMgPD0gNClcblxuIyBDb2xvcmVkIGhpc3RvZ3JhbXNcbmdncGxvdChnYW1lc19zdWIsIGFlcyh4ID0gYXZlcmFnZV9yYXRpbmcsIGZpbGwgPSBmYWN0b3IobWluX3BsYXllcnMpKSkgK1xuICAgIGdlb21faGlzdG9ncmFtKClcblxuIyBDb2xvcmVkIGRlbnNpdHkgcGxvdHNcbmdncGxvdChnYW1lc19zdWIsIGFlcyh4ID0gYXZlcmFnZV9yYXRpbmcsIGNvbG9yID0gZmFjdG9yKG1pbl9wbGF5ZXJzKSkpICtcbiAgICBnZW9tX2RlbnNpdHkoKSJ9
Phase 6
- Using the code below, construct a visualization of the relationship between minimum recommended play time and average rating (a scatterplot).
- Is the plot useful? Why or why not?
- Using the
dplyr::filter
part of the Phase 5 code, subset the data to only keep games where the minimum recommended playtime is less than 1000 minutes. Then remake the scatterplot.
- Make note of any interesting findings.
eyJsYW5ndWFnZSI6InIiLCJwcmVfZXhlcmNpc2VfY29kZSI6ImxpYnJhcnkoZ2dwbG90MilcbmxpYnJhcnkoZHBseXIpXG5saWJyYXJ5KHJlYWRyKVxuZ2FtZXMgPC0gcmVhZHI6OnJlYWRfY3N2KFwiaHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3Jmb3JkYXRhc2NpZW5jZS90aWR5dHVlc2RheS9tYXN0ZXIvZGF0YS8yMDE5LzIwMTktMDMtMTIvYm9hcmRfZ2FtZXMuY3N2XCIpIiwic2FtcGxlIjoiIyBSZWxhdGlvbnNoaXAgYmV0d2VlbiBtaW4uIHJlY29tbWVuZGVkIHBsYXkgdGltZSBhbmQgYXZlcmFnZSByYXRpbmdcbmdncGxvdChnYW1lcywgYWVzKHggPSBtaW5fcGxheXRpbWUsIHkgPSBhdmVyYWdlX3JhdGluZykpICtcbiAgICBnZW9tX3BvaW50KCkgK1xuICAgIGdlb21fc21vb3RoKClcblxuIyBTdWJzZXQgdGhlIGRhdGEgdG8gb25seSBrZWVwIGdhbWVzIHdoZXJlIHRoZVxuIyBtaW5pbXVtIHJlY29tbWVuZGVkIHBsYXl0aW1lIGlzIGxlc3MgdGhhbiAxMDAwIG1pbnV0ZXNcblxuXG4jIFJlbGF0aW9uc2hpcCBiZXR3ZWVuIG1pbi4gcmVjb21tZW5kZWQgcGxheSB0aW1lIGFuZCBhdmVyYWdlIHJhdGluZyJ9
Phase 7
- What other questions would you like to explore? Try them out below.
- If you would like to try something that is not part of the above examples, feel free to brainstorm with the instructor.
eyJsYW5ndWFnZSI6InIiLCJwcmVfZXhlcmNpc2VfY29kZSI6ImxpYnJhcnkoZ2dwbG90MilcbmxpYnJhcnkoZHBseXIpXG5saWJyYXJ5KHJlYWRyKVxuZ2FtZXMgPC0gcmVhZHI6OnJlYWRfY3N2KFwiaHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3Jmb3JkYXRhc2NpZW5jZS90aWR5dHVlc2RheS9tYXN0ZXIvZGF0YS8yMDE5LzIwMTktMDMtMTIvYm9hcmRfZ2FtZXMuY3N2XCIpIiwic2FtcGxlIjoiIyBZb3VyIG93biBleHBsb3JhdGlvbnMhIn0=