History Plotting repeats. Let’s dive into ggplot2 and repeat what we’ve done in base R using the “grammar of graphics”.

Here’s the GESIS Panel data again.

library(dplyr)
library(haven)

gp_covid <- 
  read_sav(
    "./data/ZA5667_v1-1-0.sav"
  ) %>% 
  sjlabelled::set_na(na = c(-1:-99, 97:98))

1

Create a scatter plot for the variables political_orientation and hzcy001a.
Remember the order of layers: data + aesthetics + geoms

2

Add some jitter to the scatter plot.
In contrast to the base R function jitter does not have to be added; it just replaces the original geom using geom_jitter()

3

Boxplots are boring, right? Try to plot the relationship between hzcy001a and political_orientation as a violin plot! Have a look here for reference: https://ggplot2.tidyverse.org/reference/

What’s the difference to a boxplot?
You can’t find the proper geom? Try geom_violin().