── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dslabs)data("mice_weigths")
Plot scatterplot with line of best fit using geom_point and geom_smooth
mice_weights |>ggplot(aes(x = bone_density, y = body_weight, color = body_weight)) +geom_point(stat ="identity", alpha =0.8)+geom_smooth(stat ="smooth", method ="lm", se =FALSE, col="navy") +theme_bw(base_size =14, base_family ="cambria")+labs(x ="Bone Density of Mouse",y ="Weight of Mouse",title ="Mouse Weight by Density of Bone",caption ="Source: Dataset from DSLabs R package")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 4 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
I was very excited to see that there was a dataset for mice included in dslabs. I created a scatterplot, which I have never coded from scratch before, and added a line of best fit using linear model and included standard error. At first, I started with a bar graph comparing bone density to diet, but then realized bar graphs weren’t allowed, so changed to a scatterplot. I know that the r-value for this plot is definitely relatively low and positive. Initially, I wanted to use theme_clean() because I really liked the way it looked, but for some reason this created an error with render. I used process of elimination to determine what was causing the error; nothing about it seemed to indicate it was the style of the graph.