#Load libraries

library(ggplot2)
library(scales)
library(extrafont)
## Registering fonts with R
#import .CSV data

E_Commerce <- read.csv("C:\\Users\\corey\\OneDrive\\Desktop\\CSV data\\Commerce Data - ecommerce_dataset_updated.csv", header = TRUE, stringsAsFactors = FALSE)
#displays top chunk of dataframe

head(E_Commerce)
#displays bottom chunk of dataframe

tail(E_Commerce)
#displays structure of dataframe

str(E_Commerce)
## 'data.frame':    3660 obs. of  12 variables:
##  $ User.ID       : chr  "337c166f" "d38a19bf" "d7f5f0b0" "395d4994" ...
##  $ Product.ID    : chr  "f414122f-e" "fde50f9c-5" "0d96fc90-3" "964fc44b-d" ...
##  $ Category      : chr  "Sports" "Clothing" "Sports" "Toys" ...
##  $ Price         : num  36.5 232.8 317 173.2 244.8 ...
##  $ Discount      : int  15 20 25 25 20 50 5 20 5 50 ...
##  $ Final.Price   : chr  "$31.05" "$186.23" "$237.76" "$129.89" ...
##  $ Product.Cost  : num  31 70 34 64 85 13 34 3 8 62 ...
##  $ Payment.Method: chr  "Net Banking" "Net Banking" "Credit Card" "UPI" ...
##  $ Purchase.Date : chr  "12-11-2024" "09-02-2024" "01-09-2024" "01-04-2024" ...
##  $ Qty.Sold      : int  99 63 81 47 31 46 20 67 81 17 ...
##  $ Revenue       : int  3074 11732 19259 6105 6071 5563 1461 11429 29226 3531 ...
##  $ Profit        : num  0.05 116.23 203.76 65.89 110.84 ...
#chart revenue by category

ggplot(E_Commerce, mapping=aes(x=Category, y=Revenue, fill=Category))+
  geom_col(width=0.5)+
  scale_fill_manual(values = c("#FCFED4", "#CCEDB1", "#41B7C4",
  "#Ff7f50","#68a0b0","#Edc9af","#76A973"))+
  labs(x=" ", y=" ", fill="Department")+
  scale_y_continuous(labels=label_number(scale=1e-6, suffix="M"))+
  labs(title="Revenue by Department")+
  theme(plot.title=element_text(hjust=0.5, color="#24A1BC", face="bold", size=15))+
  theme(text=element_text(color="#39FF14", face="bold", size=12))+
  theme(axis.text.x=element_blank())+
  theme(legend.title=element_text(
    face="bold",
    color="#39FF14",
    size=14))

#chart profit by category  

ggplot(E_Commerce, mapping=aes(x=Category, y=Profit, fill=Category))+
  geom_col(width=0.5)+
  scale_fill_manual(values = c("#FCFED4", "#CCEDB1", "#41B7C4",
  "#Ff7f50","#68a0b0","#Edc9af","#76A973"))+
  labs(x=" ", y=" ", fill="Department")+
  ylim(0,100000)+
  labs(title="Profit by Department")+
  theme(plot.title=element_text(hjust=0.5, color="#24A1BC", face="bold", size=15))+
  theme(text=element_text(color="#39FF14", face="bold", size=12))+
  theme(axis.text.x=element_blank())+
  theme(legend.title=element_text(
    face="bold",
    color="#02066F",
    size=14))
## Warning: Removed 393 rows containing missing values or values outside the scale range
## (`geom_col()`).