Skip to content
0

Motorcycle Parts Analysis (Daniel Santiago)

💪 Challenge

Create a report to answer your colleague's questions. Include:

  1. What are the total sales for each payment method?
  2. What is the average unit price for each product line?
  3. Create plots to visualize findings for questions 1 and 2.
  4. [Optional] Investigate further (e.g., average purchase value by client type, total purchase value by product line, etc.)
  5. Summarize your findings.

The Dataset Columns:

  • "date" - The date, from June to August 2021.
  • "warehouse" - The company operates three warehouses: North, Central, and West.
  • "client_type" - There are two types of customers: Retail and Wholesale.
  • "product_line" - Type of products purchased.
  • "quantity" - How many items were purchased.
  • "unit_price" - Price per item sold.
  • "total" - Total sale = quantity * unit_price.
  • "payment" - How the client paid: Cash, Credit card, Transfer.

Loading the packages and the dataset

library(tidyverse) #Loading "tidyverse" Package 
sales_data <- read.csv(file = "sales_data.csv") #Naming the dataset "sales_data" and loading it

sales_data #Showing dataset

1. What are the total sales for each payment method?

Finding the total sales for each payment type

total_sales_payment <- sales_data %>% #Assigning name to summarized dataframe
group_by(payment) %>% #Grouping data by each payment method
summarize(total_sale = sum(total)) #Sumarizing new dataframe showing the total sales per payment method

total_sales_payment #Showing dataframe

1.1 Graphic: Total Sales for Each Payment Type


total_sales_payment <- sales_data %>% 
group_by(payment) %>%
summarize(total_sale = sum(total))



graph_sales_payment <- ggplot(total_sales_payment, aes(x=payment, y=total_sale, fill = payment)) + geom_col() +xlab("Payment Method") + ylab("Total Sales") #Creating column chart

graph_sales_payment #Showing column chart

2. What is the Average Unit Price for each Product Line?

Finding the average unit price for each product line

avg_price_unit <- sales_data %>% #Assigning name to new dataframe
group_by(product_line) %>% #Grouping data by each product line
summarize( avg_unit_price = mean(unit_price)) #Summarizing data to show average unit price 

avg_price_unit #Showing dataframe

2.1 Graphic: Average Unit Price for Each Product Line

avg_price_unit <- sales_data %>%
group_by(product_line) %>%
summarize( avg_unit_price = mean(unit_price))

graph_avg_price <- ggplot(avg_price_unit, aes(x = product_line, y = avg_unit_price, fill = product_line)) + geom_col() + labs(x = NULL, y = "Average Unit Price", fill = "Product Line", title = " Average Unit Price for Each Product Line") + theme(axis.text.x = element_text(angle = 45)) #Creating column chart 

graph_avg_price #Showing column chart

3. Which Client Type Spends More?

value_purchase_client <- sales_data %>% #Assigning name to new dataframe
group_by(client_type) %>% #Grouping by each client Type
summarize(value_purchase = sum(total)) #Summarizing to show the total purchase value for each client type


total_purchase <- value_purchase_client %>% #Assigning name to new dataframe
summarize(total_sum = sum(value_purchase)) #Summarizing to show sum of all purchases for all client types


purchase_proportion <- value_purchase_client %>% #Assigning name to new dataframe
transmute(client_type, proportion = (value_purchase/289113)*100) #Creating a new "proportion" variable, showing the percentage of purchase value for each client type

purchase_proportion #Showing dataframe