Plotting data is fun. We also do it for data exploration (see the section on Exploratory Data Analysis). In these exercises, however, we just want to familiarize ourselves with some of the graphic facilities in R.
So let’s start with a simple task: creating a simple scatter plot. For this purpose, we first load the GESIS Panel COVID-19 survey data.
library(dplyr)
library(haven)
gp_covid <-
read_sav(
"./data/ZA5667_v1-1-0.sav"
) %>%
sjlabelled::set_na(na = c(-1:-99, 97:98))
Now let’s plot an actual variable from the dataset.
political_orientation
and hzcy001a
.
plot()
command.
plot(gp_covid$political_orientation, gp_covid$hzcy001a)
jitter()
function. Have a look at ?jitter
for more details on using the function.
plot(
jitter(gp_covid$political_orientation, 2),
jitter(gp_covid$hzcy001a, 2)
)
ColourPicker
add-in for more modern colors?
plot(
jitter(gp_covid$political_orientation, 2),
jitter(gp_covid$hzcy001a, 2),
col = c("#1C86EE", "#FFFFFF", "#FFFFFF")
)