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(dplyr)
library(completejourney)
## Welcome to the completejourney package! Learn more about these data
## sets at http://bit.ly/completejourney.
library(lubridate)
demographics <- demographics
transactions <- transactions_sample
products <- products
breadluvrs <- demographics %>%
  inner_join(transactions) %>%
  inner_join(products) %>%
  filter(grepl("bread", product_type, ignore.case = TRUE)) %>%
  group_by(age) %>%
  summarise(total_spending = sum(sales_value))
## Joining with `by = join_by(household_id)`
## Joining with `by = join_by(product_id)`
ggplot(breadluvrs, aes(x = age, y = total_spending)) +
  geom_bar(stat = "identity") +
  scale_y_continuous("Total Spendning", labels = scales::dollar) +
  scale_x_discrete( "Age In Years") +
  labs( title = "The Bread Winners",
        subtitle = "This is a table designed to show how much each age demographic 
        spends on bread.")

transactions %>%
  mutate(weekday = wday(transaction_timestamp, label = TRUE, abbr = FALSE)) %>%
  inner_join(demographics) %>%
  inner_join(products) %>%
  filter(department == "DRUG GM") %>%
  group_by(age, weekday) %>%
  summarise(visitors = n()) %>%
  ggplot(aes(x = visitors, y = age, fill = age)) +
  geom_bar(stat = "identity") +
  facet_wrap(~ weekday, scales = "free") +
  labs(title = "I Need To Pickup My Medicine!", subtitle = "These are a number
  of small tables designed to show how many visitors of each age demographic a 
  drug store has on any given day. (it should be noted that there are far more
  observations on the '45-54' age group as opposed to any other.)",
       x = "Number Of Visitors",
       y = "Age Group (in years)",
       fill = "Age Group") 
## Joining with `by = join_by(household_id)`
## Joining with `by = join_by(product_id)`
## `summarise()` has grouped output by 'age'. You can override using the `.groups`
## argument.

# Assuming 'transactions', 'demographics', and 'products' are your data frames

# Generate months in 'January', 'February' format from 'transaction_timestamp' and join the data sets
transactions %>%
  mutate(month = month(transaction_timestamp, label = TRUE)) %>%
  inner_join(demographics) %>%
  inner_join(products) %>%
  group_by(month, department) %>%
  summarise(total_sales = sum(sales_value)) %>%
ggplot(aes(x = month, y = total_sales, fill = department)) +
  geom_bar(stat = "identity", position = "stack") +
  scale_y_continuous("Total Spendning", labels = scales::dollar) +
  scale_x_discrete( "Months Of The Year") +
  labs( title = "Its Beginning To Look A Lot Like Christmas",
        subtitle = "This is a table designed to investigate a possible season 
        seasonal spending trend that could exist in consumers.") +
  theme_minimal()
## Joining with `by = join_by(household_id)`
## Joining with `by = join_by(product_id)`
## `summarise()` has grouped output by 'month'. You can override using the
## `.groups` argument.