demographics %>%
  inner_join(transactions_sample, by = "household_id") %>%
  group_by(income) %>%
  summarize(total = sum(sales_value)) %>%
  ggplot(aes(x = income, y= total, fill = factor(ifelse(income == "50-74K","Highest", "Normal")))) +
  geom_bar(stat="identity") + 
  scale_fill_manual(name="income", values=c("turquoise","grey50")) +
  scale_y_continuous(name = "Total Amount of Money Spent", labels = scales::dollar) +
  labs(
    title = "Which Income Range Spends the Most Amount of Money",
    subtitle= "This data has been collected over the past five years and sums the total amount
  of money each income range spends at a grocery store",
    x = "Income Range"
    )+
  geom_text(aes(x= "50-74K", y = max(total)+1000, label = round(max(total))))

products %>%
  inner_join(promotions_sample, by = "product_id") %>%
  inner_join(coupons, by = "product_id") %>%
  group_by(department, store_id) %>%
  count(coupon_upc) %>%
  summarize(total=sum(n)) %>%
  arrange(desc(total)) %>%
  filter(total >= 11000) %>%
  ggplot(aes(x = total, fct_reorder(department, total), color = store_id,)) +
  geom_point() +
  facet_wrap(~ store_id) +
  scale_x_continuous(labels = scales::comma, breaks = c(10000, 50000,100000,200000,300000)) +
  labs(
    title = "Which Department Gives Out the Most Amount of Coupons",
    subtitle = "Data about the number of coupons given out from two different stores and the top 6 departments",
    x = "Number of Coupons Given Out",
    y = "Store Department"
  )

products %>%
  filter(str_detect(product_category, "ICE CREAM")) %>%
  distinct(product_id) %>%
  inner_join(transactions_sample, by = "product_id") %>%
  group_by(month = months(transaction_timestamp)) %>%
  summarize(total = sum(sales_value)) %>%
  ggplot(aes(x = month, y = total, group= 1)) +
  geom_point (color = "turquoise", size = 5) +
  geom_line(color = "grey50") + 
  scale_x_discrete(limits = month.name) +
  labs(
    title = "Which Month is the Most Amount of Ice Cream Sold",
    subtitle = "This data has been collected over the past five years",
    x = "Months",
    y = "Amount of Ice Cream Sold" 
    ) +
  geom_text(aes(x= "July", y = max(total)+10, label = round(max(total))))