dplyr
Load and prepare the data:
## Observations: 80
## Variables: 18
## $ ProductType <chr> "PC", "PC", "PC", "Laptop", "Laptop", "A...
## $ ProductNum <dbl> 101, 102, 103, 104, 105, 106, 107, 108, ...
## $ Price <dbl> 949.00, 2249.99, 399.00, 409.99, 1079.99...
## $ x5StarReviews <dbl> 3, 2, 3, 49, 58, 83, 11, 33, 16, 10, 21,...
## $ x4StarReviews <dbl> 3, 1, 0, 19, 31, 30, 3, 19, 9, 1, 2, 25,...
## $ x3StarReviews <dbl> 2, 0, 0, 8, 11, 10, 0, 12, 2, 1, 2, 6, 5...
## $ x2StarReviews <dbl> 0, 0, 0, 3, 7, 9, 0, 5, 0, 0, 4, 3, 0, 8...
## $ x1StarReviews <dbl> 0, 0, 0, 9, 36, 40, 1, 9, 2, 0, 15, 3, 1...
## $ PositiveServiceReview <dbl> 2, 1, 1, 7, 7, 12, 3, 5, 2, 2, 2, 9, 2, ...
## $ NegativeServiceReview <dbl> 0, 0, 0, 8, 20, 5, 0, 3, 1, 0, 1, 2, 0, ...
## $ Recommendproduct <dbl> 0.9, 0.9, 0.9, 0.8, 0.7, 0.3, 0.9, 0.7, ...
## $ BestSellersRank <dbl> 1967, 4806, 12076, 109, 268, 64, NA, 2, ...
## $ ShippingWeight <dbl> 25.80, 50.00, 17.40, 5.70, 7.00, 1.60, 7...
## $ ProductDepth <dbl> 23.94, 35.00, 10.50, 15.00, 12.90, 5.80,...
## $ ProductWidth <dbl> 6.62, 31.75, 8.30, 9.90, 0.30, 4.00, 10....
## $ ProductHeight <dbl> 16.89, 19.00, 10.20, 1.30, 8.90, 1.00, 1...
## $ ProfitMargin <dbl> 0.15, 0.25, 0.08, 0.08, 0.09, 0.05, 0.05...
## $ Volume <dbl> 12, 8, 12, 196, 232, 332, 44, 132, 64, 4...
Using dplyr
to prepare the data:
ex_prod %>%
mutate(Total_profit = Price*Volume*ProfitMargin) %>%
group_by(ProductType) %>%
summarise(Total_Volume = sum(Volume),
Total_Profits = sum(Total_profit)) %>%
mutate(Total_Profits_Dol = paste(round((Total_Profits), 0),"$")) %>%
arrange(desc(Total_Profits)) -> categories_analysis
kable(categories_analysis %>% select(-Total_Profits)) %>%
kable_styling(bootstrap_options = "striped", full_width = F, position = "center")
ProductType | Total_Volume | Total_Profits_Dol |
---|---|---|
ExtendedWarranty | 9876 | 706083 $ |
Display | 2428 | 268089 $ |
GameConsole | 8720 | 223998 $ |
Smartphone | 1808 | 81927 $ |
Tablet | 948 | 73639 $ |
Software | 4268 | 71774 $ |
Accessories | 25548 | 54640 $ |
Printer | 2036 | 51800 $ |
Laptop | 516 | 39151 $ |
PC | 116 | 11203 $ |
Netbook | 92 | 3848 $ |
PrinterSupplies | 44 | 452 $ |
p1 <- categories_analysis %>%
arrange(Total_Profits) %>%
ggplot(aes(x = reorder(ProductType, Total_Profits))) +
geom_col(aes(y = Total_Profits), fill = "gold") +
geom_col(aes(y = -Total_Volume), fill = "dodgerblue3") +
geom_label(aes(x = ProductType, y = Total_Profits,
label = Total_Profits_Dol),
hjust = 0,
vjust = 0.4,
colour = "goldenrod3",
fill = NA,
label.size = NA,
size = 3.5) +
geom_label(aes(x = ProductType, y = -Total_Volume,
label = round(Total_Volume, 0)),
hjust = 1,
vjust = 0.4,
colour = "dodgerblue4",
fill = NA,
label.size = NA,
size = 3.5)
p1
p2 <- p1 +
coord_flip()
p2
p3 <- p2 +
scale_y_continuous(limits = c(-80000, 780000), labels = NULL)
p3
# Create a graph to understand Blackwell's business
p4 <- p3 +
labs(title = "Blackwell overview",
subtitle = "Total Volume (items) vs Total Profits ($)") +
theme_void()
p4
p5 <- p4 +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_text())
p5