Data preparation
# Loading the file
library(readxl)
Copy_of_Financial_Sample_1_ <- read_excel("Copy of Financial_Sample(1).xlsx")
#View the dataset
View(Copy_of_Financial_Sample_1_)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ 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
colnames(Copy_of_Financial_Sample_1_)
## [1] "Segment" "Country" "Product"
## [4] "Discount Band" "Units Sold" "Manufacturing Price"
## [7] "Sale Price" "Gross Sales" "Discounts"
## [10] "Sales" "COGS" "Profit"
## [13] "Date" "Month Number" "Month Name"
## [16] "Year"
Data cleaning
financial_sample <- Copy_of_Financial_Sample_1_ %>%
rename(units_sold = `Units Sold`, manufacturing_price = `Manufacturing Price`, month_number = `Month Number`, sales_price = `Sale Price`, month_name = `Month Name`, discount_band = `Discount Band`, gross_sales = `Gross Sales`) %>%
rename_with(tolower, everything())
View(financial_sample)
financial_sample_1 <- financial_sample %>%
distinct()
View(financial_sample_1)
data visualization
library(ggplot2)
ggplot(data = financial_sample_1) +
geom_bar(mapping = aes(x = country, fill = product), position = "dodge") +
labs(title = "Comparison of Products Sold by Country")

### Paseo is the highest product sold by each country, and canada sold more of it compared to other country.
ggplot(data = financial_sample_1) +
geom_bar(mapping = aes(x = product, fill = profit), fill = "pink") +
labs(title = "Comparison of Products Sold vs profit made")

### Paseo generated the highest profit for the company
ggplot(data = financial_sample_1, aes(x = country, y = sales, fill = country)) +
geom_bar(stat = "sum") +
labs(title = "Sum of Sales by Country", x = "Country", y = "Sum of Sales") +
theme_minimal()

### The United state of America sold more of all products.
ggplot(data = financial_sample_1)+geom_col(mapping = aes(x = country, y = profit), fill = "red")+
labs(title = "Profit gained per country")

### Eventhough United States of America sold more of all products, France made the highest profit of nearly 4,000,000 of all product sold
ggplot(data = financial_sample_1) + geom_bar(mapping = aes(x = segment, fill = product))+
labs(title = "Product sold per segment")

### The government segment sold 300 of all products, while the other segments sold 100 each of all products
ggplot(data = financial_sample_1)+geom_col(mapping = aes(x = segment, y = profit), fill = "purple")+
labs(title = "Profit gained per segment")

### The government segment made over 80,000,000 of all products, which is more than 80% of all profit generates
ggplot(data = financial_sample_1)+geom_col(mapping = aes(x = year, y = profit), fill = "orange")+
labs(title = "Profit gained per year")

### Two times the profit made in 2013, was made in 2014.