set.seed(301)
n <- 50
study_hours <- runif(n, min = 1, max = 10)
exam_score <- 50 + 5 * study_hours + rnorm(n, sd = 8)
df <- data.frame(study_hours, exam_score)
fit <- lm(exam_score ~ study_hours, data = df)
p1 <- ggplot(df, aes(x = study_hours, y = exam_score)) +
geom_point(color = "#8C1D40", size = 2) +
geom_smooth(method = "lm", formula = y ~ x, color = "black", se = TRUE) +
labs(x = "Study Hours", y = "Exam Score", title = "Exam Score vs. Study Hours") +
theme_minimal()
I made up a realistic dataset since I didn’t have a real one handy: study_hours between 1 and 10, exam_score going up with study hours plus some noise. lm() fits the model, and this same chunk builds the plot on the next slide.