From 31534d61a7de7640946e17a8da5c47073102c7c3 Mon Sep 17 00:00:00 2001 From: Lawrence De Geest Date: Sat, 27 May 2023 15:43:29 -0700 Subject: [PATCH] Update moviestar.R Added regression lines to plots, and combined two plots into one. --- R/moviestar.R | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/R/moviestar.R b/R/moviestar.R index 70185f2..71cc49c 100644 --- a/R/moviestar.R +++ b/R/moviestar.R @@ -1,4 +1,5 @@ library(tidyverse) +library(patchwork) set.seed(3444) @@ -10,20 +11,17 @@ star_is_born <- tibble( star = ifelse(score>=c85,1,0) ) -star_is_born %>% - lm(beauty ~ talent, .) %>% +p1 = star_is_born %>% ggplot(aes(x = talent, y = beauty)) + - geom_point(size = 0.5, shape=23) + xlim(-4, 4) + ylim(-4, 4) + geom_point(size = 1, alpha = 0.5) + xlim(-4, 4) + ylim(-4, 4) + + geom_smooth(method = 'lm', se = FALSE) + + labs(title = "Everyone") -star_is_born %>% - filter(star == 1) %>% - lm(beauty ~ talent, .) %>% - ggplot(aes(x = talent, y = beauty)) + - geom_point(size = 0.5, shape=23) + xlim(-4, 4) + ylim(-4, 4) - -star_is_born %>% - filter(star == 0) %>% - lm(beauty ~ talent, .) %>% - ggplot(aes(x = talent, y = beauty)) + - geom_point(size = 0.5, shape=23) + xlim(-4, 4) + ylim(-4, 4) +p2 = star_is_born %>% + ggplot(aes(x = talent, y = beauty, color = factor(star))) + + geom_point(size = 1, alpha = 0.25) + xlim(-4, 4) + ylim(-4, 4) + + geom_smooth(method = 'lm', se = FALSE) + + labs(title = "Everyone, but different") + + scale_color_discrete(name = 'Star') +p1 + p2