Import data

For this hands on practice, load the spi data set from the psych package.

# Load data and convert sex and education to factors
data("spi", package="psych")
spi <- spi %>% 
  dplyr::rename(exercise = exer) %>%
  dplyr::select(age, sex, health, p1edu, p2edu, 
                education, wellness,
                exercise, smoke, ER) %>%
  mutate(sex=factor(sex, levels=c(1,2), 
                    labels=c("male", "female")),
         wellness=factor(wellness, levels=c(1,2), 
                         labels=c("Low", "High")),
         exercise=factor(exercise, levels=c(1,2,3), 
                         labels=c("Rarely", "Sometimes", "Often")),
         ER=factor(ER, levels=c(1,2,3,4), 
                   labels=c("None", "1x", "2x", "3+"))) %>%
  na.omit()

Visualization Exercises

  1. Check the help file, structure, and first few observations of the data and the structure of the data.
# Write your code here!
  1. Examine the distribution of your continuous variables.
# Write your code here!
  1. Create a scatter plot that examines the relation between age and health.
# Write your code here!
  1. Add a categorical variable to your scatterplot such as sex or exercise using color and/or shape as the asthetic. Try playing with the alpha level of the points.
# Write your code here!
  1. Add a regression line to your scatterplot
# Write your code here
  1. Try using ggpairs to examine multiple relations between your variables simultaneously. You can examine the entire dataset or select particular variables to include using dplyr::select() in the pipe.
# Write your code here!
  1. Use a bar graph to examine a count of ER visits.
# Write your code here!
  1. Use a bar graph to examine mean health by ER visits.
# Write your code here!
  1. Create a bar graph examining health by ER visits with error bars using Rmisc and summarySE().
# Write your code here!
  1. Use a bar graph to examine a three way interaction between health, ER and sex. Hint: Use color to define sex.
# Write your code here!
  1. Say you were interested in relations between health, wellness and sex. How would you visualize this relation?
# Write your code here!
  1. Try exporting one of your favorite plots you made!
# Write your code here!