this is the nav!
Workspace
Joshua Wright/

# Analysis of Motorcycle Sales Data

0
Beta

#Analysis of Total Sales and Average Price per Unit from June 1, 2021 to August 28, 2021

```.mfe-app-workspace-qcdhrn{font-size:13px;line-height:1.5384615384615385;font-family:JetBrainsMonoNL,Menlo,Monaco,'Courier New',monospace;}```library(tidyverse)
library(lubridate)

#### Calculates and visualizes total sales for each payment method.

1. What are the total sales for each payment method?
``````df %>%
group_by(payment) %>%
summarize(total_sales = sum(total))

df %>%
mutate(payment = factor(payment, levels=c("Cash", "Credit card", "Transfer"))) %>%
ggplot(aes(x = payment, y = total)) +
geom_col() +
labs(title = "Total Sales by Payment Method", x = "Payment Method", y = "Total Sales (USD)", caption = "Total Sales of \$289113") +
scale_y_continuous(labels = scales::dollar) +
theme_bw()``````

#### Calculates and visualizes average unit price for each product line.

1. What is the average unit price for each product line?
``````df %>%
group_by(product_line) %>%
summarize(avg_unit_price = mean(unit_price))

df %>%
mutate(product_line = factor(product_line, levels=c("Breaking system", "Miscellaneous", "Electrical system",
"Suspension & traction", "Frame & body", "Engine"))) %>%
ggplot(aes(x = product_line, y = unit_price)) +
geom_bar(stat = "summary", fun = "mean") +
labs(title = "Average Unit Price by Product Line", x = "Product Line", y = "Average Unit Price (USD)") +
scale_y_continuous(labels = scales::dollar) +
theme_bw() +
coord_flip()``````
1. [Optional] Investigate further (e.g., average purchase value by client type, total purchase value by product line, etc.)

###Calculates and visualizes total sales across June, July, and August by client type.

``````df %>%
mutate(month_of_year = month(date)) %>%
group_by(month_of_year) %>%
summarize(total_sales = sum(total)) %>%
ungroup()

df %>%
mutate(month_of_year = month(date)) %>%
group_by(month_of_year, client_type) %>%
summarize(total_sales = sum(total)) %>%
ungroup()

df %>%
group_by(client_type) %>%
summarize(total_sales = sum(total)) %>%
ungroup()

df %>%
mutate(month_of_year = month(date)) %>%
ggplot(aes(x = month_of_year, y = total)) +
geom_col() +
labs(title = "Total Sales by Month and Client Type", x = "Month", y = "Total Sales (USD)") +
scale_y_continuous(labels = scales::dollar) +
theme_bw() +
facet_wrap(~ client_type)``````