Skip to main content

Section 10.5 A Scatterplot of Low Self-Control and Risky Lifestyles

We can create a scatterplot of low self-control and risky lifestyles to explore the relationship between these two variables.
library(tidyverse)
Inmate_Survey %>%
  ggplot(aes(x = LSC, y = RL, color = "Points")) +
  geom_point(aes(size = "id"), color = "purple", alpha = 0.5) +
  geom_smooth(aes(color = "Linear fit line"), method = "lm", se = FALSE) +
  theme_minimal() +
  labs(y = "Risky Lifestyles", x = "LSC", color = "", shape = "") +
  scale_size_manual(values = 2, name = "")
The graph above should give us a general idea regarding a bivariate relationship between the two variables. The geom_smooth() function with method = "lm" is used to add a linear regression line to the plot, which represents the best-fit straight line through the data points. The aes(color = "Linear fit line") part specifies that the color of this linear fit line will be labeled as “Linear fit line” in the legend, making it distinguishable from other elements in the plot. Setting se = FALSE means that the standard error bands around the linear regression line will not be displayed on the plot. These bands are typically shown by default to indicate the uncertainty or variability of the regression line, but in this case, they are disabled. This line goes up from left to right, showing a positive relationship between low self-control and risky lifestyles. Those with low self-control were more likely to engage in risky lifestyles, which makes sense.