The business problem that I have chosen to look at is the marketing strategy currently used for milk and cereal sales.
By filtering through the data set, I can find the percentage of people who buy cereal as well as milk. I can also determine the demographic who purchases the most of these two separate products.
By using this data Regork can change their marketing strategy to better understand their customer base and to increase sales.
Complete Journey : Provides the data necessary to come to our conclusion.
tidyverse: Provides the necessary packages used to manipulate data into the variables that we are interested in
ggplot2: provides the graphing capabilities used to create graphs in the document.
# Load Packages
library(completejourney)
library(tidyverse)
library(ggplot2)
library(lubridate)
# Load Transactions, Products, and Demographics Data
transactions <- get_transactions()
products <- products
demographics <- demographics
# Join demographics and transactions data
trans_by_demog <- inner_join(demographics,transactions)
#join transactions/demographics data with product data
trans_by_demog_by_prod <- left_join(trans_by_demog, products)
# Narrow Data into variables we care about
narrowed_data <- select(trans_by_demog_by_prod, age, income, household_size, basket_id, transaction_timestamp, product_category, product_type)
Joining all the data using the code above, we can find the variables that we are interested in and see how they relate to one another. We can used the narrowed_data in the final step to start to analyze the data.
The above table is the full join of all of the data in which we are interested in.
# Filter narrowed data to find all white milk purchases
milk_purchases <- filter(narrowed_data, product_type == "FLUID MILK WHITE ONLY")
# Filter narrowed data to find all cereal purchases
cereal_purchases <- filter(narrowed_data, grepl("COLD CEREAL", product_category))
# Join filtered data sets together
milk_and_cereal <- full_join(milk_purchases,cereal_purchases)
After the code above is executed, we can find three different points of interest. First we find all of the White Milk purchases by running the first line, second, we find all the cereal purchases in the data, last we join these two filtered data sets together.
Below is the data table of both cereal and milk transactions.
rmarkdown::paged_table(milk_and_cereal)
ggplot(data = milk_and_cereal, aes(x = product_category)) +
geom_bar() +
facet_wrap( ~ age) +
ggtitle("Milk and Cereal Purchases By Age Group") +
xlab("Products") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
ylab("Count")
Using the joined milk and cereal transactions, we can execute the code above to graph a bar chart showing the milk and cereal purchased by age range.
In order, the age groups that buy the most milk and cereal are 45-54 years old, 35-44 years old, and 25-34 years
ggplot(data = milk_and_cereal, aes(x = product_category)) +
geom_bar() +
facet_wrap( ~ income) +
coord_cartesian(ylim = c(0, 8000)) +
ggtitle("Milk and Cereal Purchases By Income Range") +
xlab("Products") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
ylab("Count")
again using the milk and cereal transactions, we can create a graph
which shows what income ranges purchase the most milk and cereal.
The Income ranges that purchase the most milk and cereal are 35-49k, 50-74k, and 75-99k.
# Create Data that shows transactions that include both cereal and milk
milk_and_cereal$transaction_timestamp <- as.POSIXct(milk_and_cereal$transaction_timestamp)
milk_and_cereal <- milk_and_cereal %>%
arrange(transaction_timestamp)
result <- milk_and_cereal %>%
group_by(basket_id, transaction_timestamp) %>%
filter(n_distinct(product_category) >= 2)
rmarkdown::paged_table(result)
# Calculate the percentage of transactions with both cereal and milk
result <- result %>%
mutate(pct = n_distinct(result) / n_distinct(milk_and_cereal))
After calculating the percentage of transactions that include both milk and cereal, we find that approximately 38.7% of people that buy milk, buy cereal at the same time.
This analysis was meant to see what groups of people we should be marketing to based on age and income, and whether or not we should run joint marketing campaigns for both milk and cereal, or if we should market them separately.
To start, I joined the data from three data frames, which were transactions, products, and demographics. Using the combined data frame, I narrowed the data by selecting only the variables in which we were interested in. After this, I used the narrowed data to find all milk and cereal transactions. I then graphed the milk and cereal transactions by age range. In this graph, I found the three main age groups in which we should be marketing to.After this I graphed milk and cereal sales by income and found what range of income we should be marketing to. After this, I compiled a list of all transactions which included both milk and cereal in the basket, and found that around 38% of people buy milk and cereal in the same transaction.
I recommend that we market heavily to the top three age groups and income ranges found in the report. I do not believe that there is enough link between milk and cereal sales to run a join marketing campaign, so these products should continue to be marketed separate.