- Using the
mpg
data, create a data object called class_cyl
that subsets only the compact and midsize class cars with 4 or 6 cylinders and makes cylinder number a factor. You should end up with 84 observations.
- Create an interaction plot from
class_cyl
with cylinder number on the x-axis, highway fuel efficiency on the y-axis, and separately colored lines for class. Spatially separate overlapping error bars.
- Repeat interaction plot #2, reversing the roles of class and cylinder number by making class the x-axis and cylinder number the lines. Do the two plots communicate information differently? Which do you prefer?
- Take the
class_cyl
data and calculate the mean and standard error for each combination of class and cylinder number levels. Note that you can calculate standard error by dividing the standard deviation by the square root of the sample size. Next, create a column that subtracts SE from mean for the lower bound and add SE to mean for the upper bound. Assign these means, standard errors, and lower and upper bounds to mean_mpg
(you should have 4 observations and 6 variables).
- Replicate plot #3 using the
mean_mpg
data set by plotting the means and bounds as error bars and include a line connecting across class. Is it identical to plot #3?
- Using
class_cyl
, calculate the mean highway fuel efficiency for each manufacturer and cylinder size. Plot a slopegraph of dashed lines for each manufacturer connecting the mean fuel efficiency for 4 and 6 cylinders. Overlay the mean and standard deviation across manufacturers for both levels of cylinder number.
- Using
mpg
, create a raincloud plot that includes a half density plot and half dot plot of highway fuel efficiency for each class. Adjust the bin width and dot size to produce a reasonable distribution of dots. Color the lines and shaded areas differently for each class, but remove the legend. Reduce the opacity of the shaded areas.