Visualizing parallel slopes
The two plots in the previous exercise gave very different predictions: one gave a predicted response that increased linearly with a numeric variable; the other gave a fixed response for each category. The only sensible way to reconcile these two conflicting predictions is to incorporate both explanatory variables in the model at once.
When it comes to a linear regression model with a numeric and a categorical explanatory variable, ggplot2 doesn't have an easy, "out of the box" way to show the predictions. Fortunately, the moderndive package includes an extra geom, geom_parallel_slopes() to make it simple.
taiwan_real_estate is available; ggplot2 and moderndive are loaded.
Diese Übung ist Teil des Kurses
Intermediate Regression in R
Anleitung zur Übung
- Using the
taiwan_real_estatedataset, plot house prices versus the number of nearby convenience stores, colored by house age. - Make it a scatter plot.
- Add parallel slopes, without a standard error ribbon.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Using taiwan_real_estate, plot price_twd_msq vs. n_convenience colored by house_age_years
___ +
# Add a point layer
___ +
# Add parallel slopes, no ribbon
___