dslabs: divorce and margarine

Author

Kevin Sanchez

Install Packages

library(tidyverse)
── 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.4.4     ✔ 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")
library(RColorBrewer)
data("divorce_margarine")
library(ggthemes)
library(ggrepel)

Graph

ds_theme_set()
divorce_margarine %>% 
  ggplot(aes(x = divorce_rate_maine, y = margarine_consumption_per_capita, label = year)) +
  geom_text_repel(nudge_x = 0.005) +
  geom_point(aes(color=divorce_rate_maine), size = 4) +
  geom_text_repel(nudge_x = 0.005) +
  xlab("Divorce Rate Maine") +
  ylab("Margarine Consumption Per Capita") +
  ggtitle("Divorce Rate and Margarine Consumption")

Summary

  • I created a scatterplot using the “divorce_margarine” dataset which shows the data on divorce rate in Maine and the margarine consumption par capita for the years from 2000 to 2009. In the scatterplot, I attempted to depict the correlation between the divorce rate and margarine consumption. I used ggplot to create the graph and I used divorce rate in Maine as my x and Margarine consumption per capita as my y. The points on the graph were given years to better understand the correlation and the legend shows that the darker the blue, the lower the rate is and vice verse. As the graph shows, in the year 2000, the margarine consumption was higher as the divorce rate was higher. Does getting divorced cause you to eat more margarine? Or does eating more margarine cause you to get a divorce. I don’t really see a correlation nor does it make sense.