```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) # handy package manager that installs and loads packages used in this document if (!("pacman" %in% installed.packages()[,"Package"])) { install.packages("pacman") } pacman::p_load(tidyverse, psych, GGally, Rmisc, interactions) # install (if needed) and load packages ``` # Import data For this hands on practice, load the `spi` data set from the `psych` package. ```{r load-spi} # 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. ```{r} # Write your code here! ``` 2. Examine the distribution of your continuous variables. ```{r} # Write your code here! ``` 3. Create a scatter plot that examines the relation between age and health. ```{r} # Write your code here! ``` 4. 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. ```{r} # Write your code here! ``` 5. Add a regression line to your scatterplot ```{r} # Write your code here ``` 6. 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. ```{r} # Write your code here! ``` 7. Use a bar graph to examine a count of ER visits. ```{r} # Write your code here! ``` 8. Use a bar graph to examine mean health by ER visits. ```{r} # Write your code here! ``` 9. Create a bar graph examining health by ER visits with error bars using Rmisc and summarySE(). ```{r} # Write your code here! ``` 10. Use a bar graph to examine a three way interaction between health, ER and sex. Hint: Use color to define sex. ```{r} # Write your code here! ``` 11. Say you were interested in relations between health, wellness and sex. How would you visualize this relation? ```{r} # Write your code here! ``` 12. Try exporting one of your favorite plots you made! ```{r} # Write your code here! ```