transactions_sample %>%
  inner_join(demographics, by = "household_id") %>%
  inner_join(products, by = "product_id") %>%
  group_by(income, brand) %>%
  summarize(total_sales = sum(sales_value)) %>%
  arrange(desc(total_sales)) %>%
  ggplot(aes(x = income, y = total_sales, color = brand, group = brand)) +
  geom_line(size = 1) +
  geom_point(size = 2) +
  guides(color = guide_legend(title = "Brand Type")) +
  scale_y_continuous("Total Sales", labels = scales::dollar) +
  scale_x_discrete("Customers' Income Range") +
  ggtitle("Customer Sales by Income Range and Brand Preference",
          subtitle = "Comparing store vs national brand spending across income levels.")

transactions_sample %>%
  inner_join(demographics, by = "household_id") %>%
  mutate(month = lubridate::month(transaction_timestamp, label = TRUE)) %>%
  group_by(month) %>%
  summarize(total_sales = sum(sales_value)) %>%
  arrange(desc(total_sales)) %>%
  ggplot(aes(x = month, y = total_sales, color = month)) +
  geom_point(size = 3) +
  guides(color = guide_legend(title = "Month")) +
  scale_y_continuous("Total Sales", labels = scales::dollar) +
  scale_x_discrete("Month") +
  ggtitle("Seasonal Trends in Grocery Spending",
          subtitle = "Comparing total sales trends across months.")

transactions_sample %>%
  inner_join(demographics, by = "household_id") %>%
  mutate(day_of_week = weekdays(transaction_timestamp)) %>%
  group_by(day_of_week) %>%
  summarize(total_sales = sum(sales_value)) %>%
  arrange(desc(total_sales)) %>%
  ggplot(aes(x = total_sales, y = day_of_week, fill = day_of_week)) +
  geom_bar(stat = "identity") +
  guides(fill = guide_legend(title = "Day of the Week")) +
  scale_x_continuous("Total Sales", labels = scales::dollar) +
  scale_y_discrete("Day of the Week") +
  ggtitle("Most Popular Day of the Week for Grocery Shopping",
          subtitle = "Transaction amounts across the week.")