Chapter 3 Making Graphs
3.1 Class material
Note: most of this class talk in workshop style, so any recordings are short and the slides are brief
We will work through these files as in-class exercises: class3a.R and class3b.R. These are based on Healy (2018) chapters 2 and 3 respectively.
Reading the first 3 chapters of Healy (2018) before the next class is essential
3.2 Resources
This book is recommended for the course, and for this lecture in particular:
Healy, K. (2018). Data visualization: a practical introduction. Princeton University Press.
- The whole book is available online via the link
- There are supporting materials here: https://github.com/kjhealy/socviz
3.2.1 Other resources
- We are going to be using the ggplot package for our visualisations: ggplot2
- Five Charts You’ve Never Used but Should
- guru99: Scatter Plot in R using ggplot2 (with Example)
- ggplot2: Elegant Graphics for Data Analysis, the chapter on Themes
- Giulia Ruggeri, Better data communication with {ggplot2}Styling a chart and improving the text using {forcats} and {ggtext} and {scales}, Better data communication with {ggplot2}, part 2
- datanovia.com: GGPlot Axis Ticks: Set and Rotate Text Labels
- anthonyhobday.com: [Visual design rules you can safely follow every time][https://anthonyhobday.com/sideprojects/saferules)
3.3 Post-class exercises
Review the introduction and Chapter 1 ‘Look At Data’ of Healy (2018)
Work through Chapter 2 ‘Get Started’ from 2.3 onwards (“Things to know about R”), we are ignoring the material on RMarkdown for now (we’ll get there, see here).
Work through Chapter 3 ‘Make a plot’
3.4 Checklist
Worked through the scripts linked at the top of this page
Completed the post reading from Healy (2018)
- especially section 3.8 ‘Where to go next’ in Chapter 3 ‘Make a plot’
Key concepts (chapter 2):
- variables and functions
- variables are typed (e.g. can be numeric or character)
- and how you detect what type a variable is
- indexing for variables and data frames
In the console, understood
- the shortcut keys for the assignment operator <-
- the use of tab for autocomplete
- the use up arrow to cycle through previous commands
- CTRL + ENTER to run highlighted text
Key concepts (chapter 3):
- Tidydata
- long vs wide data
- values and keys
- data variables can be continuous or factors
- The fundamental ggplot “recipe”
- plots have data, aesthetic mappings (‘aes’, ‘mappings’) and layers
- adding mappings, adding geoms, geom properties, other layers (e.g. labs)
- mappings are inherited by geom layers