library(ggplot2)
library(dslabs)
data("mice_weights")
## Warning in data("mice_weights"): data set 'mice_weights' not found
# scatterpolot
ggplot(data = mice_weights, aes(x = bone_density, y = body_weight, color = diet)) +
geom_point(size = 1.5) +
geom_smooth(method = "loess", se = TRUE) +
scale_color_manual(values = c("#164742", "#b7410e"), labels = c("Chow", "High Fat")) +
labs(x = "Bone Density", y = "Body Weight", title = "Scatterplot of Body Weight vs. Bone Density") +
theme_minimal() +
theme(
plot.background = element_rect(fill = "#adbfc2"), #change bg
panel.background = element_rect(fill = "#cebaa2"), #change inner chart
panel.grid.major = element_blank(), #getting rid of grid lines
panel.grid.minor = element_blank(),
axis.text.x = element_text(color = "black"), # x-axis
axis.text.y = element_text(color = "black"), # y-axis
text = element_text(color = "black"), #change text
plot.title = element_text(color = "black") #title
)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 4 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 4 rows containing missing values (`geom_point()`).
I used the dataset mice_weights to compare the body weight and bone density of the mice. I started by creating the scatterplot comparing the two variables, then proceeded to add my third variable which was their diet, visible by the legend on the right which denotes whether the mouse was on a chow or high fat diet.