Library

library(tidyverse)
## -- Attaching packages ---------------------------------- tidyverse 1.2.1 --
## v ggplot2 2.2.1     v purrr   0.2.4
## v tibble  1.3.4     v dplyr   0.7.4
## v tidyr   0.7.2     v stringr 1.2.0
## v readr   1.1.1     v forcats 0.2.0
## -- Conflicts ------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(readr)
library (knitr)
library(ggrepel)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout

Importing Data

Sales2012_2014 <- read_csv("C:/Users/ThuyAnh/Desktop/ITKM549/Sales_Prod_2012-14.csv")
## Parsed with column specification:
## cols(
##   `Retailer country` = col_character(),
##   `Order method type` = col_character(),
##   `Retailer type` = col_character(),
##   `Product line` = col_character(),
##   `Product type` = col_character(),
##   Product = col_character(),
##   Year = col_integer(),
##   Quarter = col_character(),
##   Revenue = col_double(),
##   Quantity = col_integer(),
##   `Gross margin` = col_double()
## )
summary(Sales2012_2014)
##  Retailer country   Order method type  Retailer type     
##  Length:88475       Length:88475       Length:88475      
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
##                                                          
##                                                          
##  Product line       Product type         Product               Year     
##  Length:88475       Length:88475       Length:88475       Min.   :2012  
##  Class :character   Class :character   Class :character   1st Qu.:2012  
##  Mode  :character   Mode  :character   Mode  :character   Median :2013  
##                                                           Mean   :2013  
##                                                           3rd Qu.:2013  
##                                                           Max.   :2014  
##                                                                         
##    Quarter             Revenue           Quantity        Gross margin     
##  Length:88475       Min.   :      0   Min.   :    1.0   Min.   :-12.8537  
##  Class :character   1st Qu.:   8184   1st Qu.:  131.0   1st Qu.:  0.3699  
##  Mode  :character   Median :  21026   Median :  333.0   Median :  0.4506  
##                     Mean   :  42638   Mean   :  780.6   Mean   :  0.4497  
##                     3rd Qu.:  50391   3rd Qu.:  816.0   3rd Qu.:  0.5201  
##                     Max.   :1635688   Max.   :67875.0   Max.   :  0.7705  
##                                                         NA's   :581

1. Rename variables

Sales12_14 <- Sales2012_2014 %>% 
  rename(Country = "Retailer country",
         OrderMethod = "Order method type",
         RetailerType = "Retailer type",
         ProductLine = "Product line",
         ProductType = "Product type",
         GrossMargin = "Gross margin")
  summary(Sales12_14)
##    Country          OrderMethod        RetailerType      
##  Length:88475       Length:88475       Length:88475      
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
##                                                          
##                                                          
##  ProductLine        ProductType          Product               Year     
##  Length:88475       Length:88475       Length:88475       Min.   :2012  
##  Class :character   Class :character   Class :character   1st Qu.:2012  
##  Mode  :character   Mode  :character   Mode  :character   Median :2013  
##                                                           Mean   :2013  
##                                                           3rd Qu.:2013  
##                                                           Max.   :2014  
##                                                                         
##    Quarter             Revenue           Quantity        GrossMargin      
##  Length:88475       Min.   :      0   Min.   :    1.0   Min.   :-12.8537  
##  Class :character   1st Qu.:   8184   1st Qu.:  131.0   1st Qu.:  0.3699  
##  Mode  :character   Median :  21026   Median :  333.0   Median :  0.4506  
##                     Mean   :  42638   Mean   :  780.6   Mean   :  0.4497  
##                     3rd Qu.:  50391   3rd Qu.:  816.0   3rd Qu.:  0.5201  
##                     Max.   :1635688   Max.   :67875.0   Max.   :  0.7705  
##                                                         NA's   :581

2. Create a table that describes total sales by country and by year and their proportion of the total revenue for each year. The resulting table should have four variables: country, year, revenue, proportion_of_revenue_year.

2.1 Total Sales each year

x<- Sales12_14 %>% 
    group_by(Year) %>% 
  summarise(Revenue = sum(Revenue))%>% 
     spread(Year, Revenue) 

2.2 Total sales and propotion of sales of each country by year

Sales_Prop <- Sales12_14 %>% 
  select(Year, Country, Revenue) %>% 
  group_by(Country, Year) %>% 
  summarise(Revenue = sum(Revenue)) %>% 
  arrange(Year) %>% 
    mutate(proportion_of_revenue_year = ifelse(Year == 2012, Revenue/x$`2012`,
                                             ifelse(Year == 2013, Revenue/x$`2013`,Revenue/x$`2014`)))
kable(Sales_Prop)
Country Year Revenue proportion_of_revenue_year
Australia 2012 25607044 0.0220904
Austria 2012 34568090 0.0298208
Belgium 2012 30396297 0.0262219
Brazil 2012 34234876 0.0295333
Canada 2012 75428386 0.0650696
China 2012 79080488 0.0682201
Denmark 2012 15893267 0.0137106
Finland 2012 47826647 0.0412585
France 2012 72237825 0.0623172
Germany 2012 65238045 0.0562787
Italy 2012 46135925 0.0397999
Japan 2012 86340230 0.0744829
Korea 2012 50844973 0.0438623
Mexico 2012 42363572 0.0365457
Netherlands 2012 44421660 0.0383211
Singapore 2012 48204223 0.0415842
Spain 2012 39237620 0.0338490
Sweden 2012 23966997 0.0206755
Switzerland 2012 26286562 0.0226766
United Kingdom 2012 69420604 0.0598869
United States 2012 201462260 0.1737949
Australia 2013 47799737 0.0319540
Austria 2013 44996737 0.0300802
Belgium 2013 38375433 0.0256539
Brazil 2013 43389954 0.0290061
Canada 2013 98134069 0.0656024
China 2013 99109352 0.0662544
Denmark 2013 20050466 0.0134037
Finland 2013 59648620 0.0398750
France 2013 83075921 0.0555361
Germany 2013 78113787 0.0522189
Italy 2013 61869049 0.0413593
Japan 2013 112137015 0.0749634
Korea 2013 60714213 0.0405873
Mexico 2013 58604265 0.0391768
Netherlands 2013 58301768 0.0389746
Singapore 2013 60942903 0.0407402
Spain 2013 55846233 0.0373331
Sweden 2013 30360527 0.0202959
Switzerland 2013 41463606 0.0277183
United Kingdom 2013 84920826 0.0567694
United States 2013 258036621 0.1724969
Australia 2014 35893189 0.0321239
Austria 2014 33801789 0.0302521
Belgium 2014 28186840 0.0252268
Brazil 2014 31440841 0.0281391
Canada 2014 73325209 0.0656250
China 2014 70633377 0.0632159
Denmark 2014 11954800 0.0106994
Finland 2014 44746716 0.0400477
France 2014 64209896 0.0574669
Germany 2014 57421832 0.0513917
Italy 2014 46625799 0.0417294
Japan 2014 83188254 0.0744523
Korea 2014 47014946 0.0420777
Mexico 2014 38401768 0.0343690
Netherlands 2014 46212968 0.0413599
Singapore 2014 47114688 0.0421670
Spain 2014 41679916 0.0373029
Sweden 2014 26308001 0.0235453
Switzerland 2014 32981707 0.0295182
United Kingdom 2014 64881658 0.0580682
United States 2014 191312080 0.1712216

3. Create two tables, using the results from question 2:

3.1 Transpose (spread) the data so you end up with four variables: country, revenue_2012, rev-enue_y2013, and revenue_y2014.

Sales_by_Year <- Sales_Prop %>% 
  select(Year, Country, Revenue) %>% 
  spread(Year, Revenue) %>% 
  rename(revenue_2012 = `2012`,
         revenue_2013 = `2013`,
         revenue_2014 = `2014`)
kable(Sales_by_Year)
Country revenue_2012 revenue_2013 revenue_2014
Australia 25607044 47799737 35893189
Austria 34568090 44996737 33801789
Belgium 30396297 38375433 28186840
Brazil 34234876 43389954 31440841
Canada 75428386 98134069 73325209
China 79080488 99109352 70633377
Denmark 15893267 20050466 11954800
Finland 47826647 59648620 44746716
France 72237825 83075921 64209896
Germany 65238045 78113787 57421832
Italy 46135925 61869049 46625799
Japan 86340230 112137015 83188254
Korea 50844973 60714213 47014946
Mexico 42363572 58604265 38401768
Netherlands 44421660 58301768 46212968
Singapore 48204223 60942903 47114688
Spain 39237620 55846233 41679916
Sweden 23966997 30360527 26308001
Switzerland 26286562 41463606 32981707
United Kingdom 69420604 84920826 64881658
United States 201462260 258036621 191312080

3.2 Transpose (spread) the data so you end up with four variables: country, prop_2012, prop_y2013,and prop_y2014.

Prop_by_Year<- Sales_Prop %>% 
  select(Year, Country, proportion_of_revenue_year) %>% 
  spread(Year, proportion_of_revenue_year) %>% 
  rename(prop_2012 = `2012`,
         prop_2013 = `2013`,
         prop_2014 = `2014`)
kable (Prop_by_Year)
Country prop_2012 prop_2013 prop_2014
Australia 0.0220904 0.0319540 0.0321239
Austria 0.0298208 0.0300802 0.0302521
Belgium 0.0262219 0.0256539 0.0252268
Brazil 0.0295333 0.0290061 0.0281391
Canada 0.0650696 0.0656024 0.0656250
China 0.0682201 0.0662544 0.0632159
Denmark 0.0137106 0.0134037 0.0106994
Finland 0.0412585 0.0398750 0.0400477
France 0.0623172 0.0555361 0.0574669
Germany 0.0562787 0.0522189 0.0513917
Italy 0.0397999 0.0413593 0.0417294
Japan 0.0744829 0.0749634 0.0744523
Korea 0.0438623 0.0405873 0.0420777
Mexico 0.0365457 0.0391768 0.0343690
Netherlands 0.0383211 0.0389746 0.0413599
Singapore 0.0415842 0.0407402 0.0421670
Spain 0.0338490 0.0373331 0.0373029
Sweden 0.0206755 0.0202959 0.0235453
Switzerland 0.0226766 0.0277183 0.0295182
United Kingdom 0.0598869 0.0567694 0.0580682
United States 0.1737949 0.1724969 0.1712216

4 Merge the results from both tables created in question 3.

Summary_Sales<- inner_join(Sales_by_Year, Prop_by_Year, by = c("Country")) %>% 
  select(1,2,5,3,6,4,7)

kable(Summary_Sales)
Country revenue_2012 prop_2012 revenue_2013 prop_2013 revenue_2014 prop_2014
Australia 25607044 0.0220904 47799737 0.0319540 35893189 0.0321239
Austria 34568090 0.0298208 44996737 0.0300802 33801789 0.0302521
Belgium 30396297 0.0262219 38375433 0.0256539 28186840 0.0252268
Brazil 34234876 0.0295333 43389954 0.0290061 31440841 0.0281391
Canada 75428386 0.0650696 98134069 0.0656024 73325209 0.0656250
China 79080488 0.0682201 99109352 0.0662544 70633377 0.0632159
Denmark 15893267 0.0137106 20050466 0.0134037 11954800 0.0106994
Finland 47826647 0.0412585 59648620 0.0398750 44746716 0.0400477
France 72237825 0.0623172 83075921 0.0555361 64209896 0.0574669
Germany 65238045 0.0562787 78113787 0.0522189 57421832 0.0513917
Italy 46135925 0.0397999 61869049 0.0413593 46625799 0.0417294
Japan 86340230 0.0744829 112137015 0.0749634 83188254 0.0744523
Korea 50844973 0.0438623 60714213 0.0405873 47014946 0.0420777
Mexico 42363572 0.0365457 58604265 0.0391768 38401768 0.0343690
Netherlands 44421660 0.0383211 58301768 0.0389746 46212968 0.0413599
Singapore 48204223 0.0415842 60942903 0.0407402 47114688 0.0421670
Spain 39237620 0.0338490 55846233 0.0373331 41679916 0.0373029
Sweden 23966997 0.0206755 30360527 0.0202959 26308001 0.0235453
Switzerland 26286562 0.0226766 41463606 0.0277183 32981707 0.0295182
United Kingdom 69420604 0.0598869 84920826 0.0567694 64881658 0.0580682
United States 201462260 0.1737949 258036621 0.1724969 191312080 0.1712216

5. Which country has highest growth rate in terms of revenue in 2013, 2014

Rev_Growth <- Sales_by_Year %>% 
  select(Country, revenue_2013, revenue_2014) %>% 
  mutate(Growth_Rate = (revenue_2014-revenue_2013)/revenue_2013) %>% 
  arrange(desc(Growth_Rate))
kable(Rev_Growth)
Country revenue_2013 revenue_2014 Growth_Rate
Sweden 30360527 26308001 -0.1334801
Switzerland 41463606 32981707 -0.2045625
Netherlands 58301768 46212968 -0.2073488
Korea 60714213 47014946 -0.2256353
Singapore 60942903 47114688 -0.2269044
France 83075921 64209896 -0.2270938
United Kingdom 84920826 64881658 -0.2359747
Italy 61869049 46625799 -0.2463793
Austria 44996737 33801789 -0.2487947
Australia 47799737 35893189 -0.2490923
Finland 59648620 44746716 -0.2498281
Canada 98134069 73325209 -0.2528058
Spain 55846233 41679916 -0.2536665
Japan 112137015 83188254 -0.2581553
United States 258036621 191312080 -0.2585855
Germany 78113787 57421832 -0.2648950
Belgium 38375433 28186840 -0.2654978
Brazil 43389954 31440841 -0.2753889
China 99109352 70633377 -0.2873187
Mexico 58604265 38401768 -0.3447274
Denmark 20050466 11954800 -0.4037645

The growth rate of every country does not look good. All of them have a decrease in their revenue comparing between 2014 to 2013. And Sweden is the country with lowest revenue decrease number 13.34%

6. Which country has highest growth rate in terms of proportion of total revenue, taking into account of 2013 - 2014

Prop_Growth <- Prop_by_Year %>% 
  select(Country, prop_2013, prop_2014) %>% 
  mutate(Growth_Rate = (prop_2014-prop_2013)/prop_2013) %>% 
  arrange(desc(Growth_Rate)) %>% 
  head(Growth_Rate, n=1L)
kable(Prop_Growth)
Country prop_2013 prop_2014 Growth_Rate
Sweden 0.0202959 0.0235453 0.1600979

Sweden is the country has the highest growth rate in term of proportion by total revenue, comparing year of 2014 to 2013

7. Bar plot

data_for_plot1 <-Sales12_14 %>% 
    select(Year, Country, Revenue) %>% 
  group_by(Country, Year) %>% 
    summarise(Revenue = sum(Revenue)) %>% 
  mutate (Year = as.factor(Year), Revenue = Revenue/1000000)
ggplot(data_for_plot1, aes(x=reorder(Country, -Revenue),
                           y=Revenue, fill=Year )) +   
  geom_bar(position='dodge', stat='identity', color="black") +
    labs (x= 'Country', 
        y = 'Revenue (million)', 
        title = 'Summary of Revenue',
        fill = "Year")+
  theme (axis.text.x = element_text(angle = 90, hjust = 1),
         panel.grid.major = element_blank(), 
         panel.grid.minor = element_blank())

8. Scatterplot

data_for_plot2 <- Rev_Growth %>% 
  select(1,3,4) %>% 
  mutate(revenue_2014 = revenue_2014/1000000)
m <- ggplot(data_for_plot2, aes(x=revenue_2014, 
                           y=Growth_Rate,
                           color=Country)) +
      geom_point(show.legend = F )+
  labs (x= 'Revenue 2014 (million)', 
        y = ' Revenue Growth Rate', 
        title = 'Revenue 2014 - Growth 2013-2014',
        legend = "Country")
  
  ggplotly(m, session = 'knitr')
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

9. Most profitable country

Sales12_14 <- Sales12_14 %>% 
  mutate (GrossProfit = Revenue*GrossMargin) %>% 
  na.omit()
Sales_Profit <- Sales12_14 %>% 
  select(Year, Country, Revenue, GrossMargin, GrossProfit) %>% 
  group_by(Country, Year) %>% 
  summarise(Revenue = sum(Revenue), GrossProfit = sum(GrossProfit)) %>% 
  arrange(Year) %>% 
    mutate(Margin = (GrossProfit/Revenue))
kable(Sales_Profit)
Country Year Revenue GrossProfit Margin
Australia 2012 25607044 10384588 0.4055364
Austria 2012 34568090 14175416 0.4100723
Belgium 2012 30396297 12339880 0.4059666
Brazil 2012 34234876 13854339 0.4046849
Canada 2012 75428386 30504205 0.4044128
China 2012 79080488 31963420 0.4041884
Denmark 2012 15893267 6438462 0.4051063
Finland 2012 47826647 19278203 0.4030850
France 2012 72237825 29313542 0.4057922
Germany 2012 65238045 26505188 0.4062842
Italy 2012 46135925 18851632 0.4086107
Japan 2012 86340230 35044742 0.4058912
Korea 2012 50844973 20542348 0.4040193
Mexico 2012 42363572 17109565 0.4038745
Netherlands 2012 44421660 17974572 0.4046353
Singapore 2012 48204223 19323204 0.4008612
Spain 2012 39237620 16061212 0.4093320
Sweden 2012 23966997 9672219 0.4035641
Switzerland 2012 26286562 10694524 0.4068438
United Kingdom 2012 69420604 28013289 0.4035299
United States 2012 201462260 81547970 0.4047804
Australia 2013 47799737 19807230 0.4143795
Austria 2013 44996737 18886350 0.4197271
Belgium 2013 38375433 16025043 0.4175860
Brazil 2013 43389954 18078456 0.4166507
Canada 2013 98134069 40958729 0.4173752
China 2013 99109352 41126760 0.4149635
Denmark 2013 20050466 8241322 0.4110289
Finland 2013 59648620 24909923 0.4176111
France 2013 83075921 34596692 0.4164467
Germany 2013 78113787 32560564 0.4168350
Italy 2013 61869049 25862271 0.4180163
Japan 2013 112137015 46843843 0.4177376
Korea 2013 60714213 25151197 0.4142555
Mexico 2013 58604265 24335576 0.4152526
Netherlands 2013 58301768 24408939 0.4186655
Singapore 2013 60942903 25312852 0.4153536
Spain 2013 55846233 23323546 0.4176387
Sweden 2013 30360527 12776374 0.4208219
Switzerland 2013 41463606 17373916 0.4190160
United Kingdom 2013 84920826 35421323 0.4171100
United States 2013 258036621 107415232 0.4162790
Australia 2014 35893189 14900245 0.4151274
Austria 2014 33801789 14202010 0.4201556
Belgium 2014 28186840 11719669 0.4157851
Brazil 2014 31440841 13128548 0.4175635
Canada 2014 73325209 30479726 0.4156787
China 2014 70633377 29398530 0.4162130
Denmark 2014 11954800 4978965 0.4164826
Finland 2014 44746716 18531797 0.4141488
France 2014 64209896 26816103 0.4176319
Germany 2014 57421832 23918484 0.4165399
Italy 2014 46625799 19497491 0.4181696
Japan 2014 83188254 34877011 0.4192540
Korea 2014 47014946 19484528 0.4144326
Mexico 2014 38401768 15879189 0.4135015
Netherlands 2014 46212968 19133312 0.4140247
Singapore 2014 47114688 19651191 0.4170927
Spain 2014 41679916 17407446 0.4176459
Sweden 2014 26308001 11016468 0.4187497
Switzerland 2014 32981707 13848073 0.4198713
United Kingdom 2014 64881658 27038316 0.4167328
United States 2014 191312080 79853980 0.4174017

9.1 Most profitable country in terms of profit

MostProfitable_Country<- Sales_Profit %>% 
  filter (Year =="2014") %>% 
  select(Country, GrossProfit) %>% 
  arrange(desc(GrossProfit))
kable(MostProfitable_Country)
Country GrossProfit
United States 79853980
Japan 34877011
Canada 30479726
China 29398530
United Kingdom 27038316
France 26816103
Germany 23918484
Singapore 19651191
Italy 19497491
Korea 19484528
Netherlands 19133312
Finland 18531797
Spain 17407446
Mexico 15879189
Australia 14900245
Austria 14202010
Switzerland 13848073
Brazil 13128548
Belgium 11719669
Sweden 11016468
Denmark 4978965

The U.S is the most profitable country

9.2 Most Profitable contry in terms of margin

HighestProfitability<- Sales_Profit %>% 
  filter (Year =="2014") %>% 
  select(Country, Margin) %>% 
  arrange(desc(Margin))
kable(HighestProfitability)
Country Margin
Austria 0.4201556
Switzerland 0.4198713
Japan 0.4192540
Sweden 0.4187497
Italy 0.4181696
Spain 0.4176459
France 0.4176319
Brazil 0.4175635
United States 0.4174017
Singapore 0.4170927
United Kingdom 0.4167328
Germany 0.4165399
Denmark 0.4164826
China 0.4162130
Belgium 0.4157851
Canada 0.4156787
Australia 0.4151274
Korea 0.4144326
Finland 0.4141488
Netherlands 0.4140247
Mexico 0.4135015

The country with highest profitability is Austria

10. Scatter plot of Revenue and Profit 2012-2014

Sliders <- ggplot(Sales_Profit, aes(x=GrossProfit/1000000, 
                                    y=Revenue/1000000, 
                                    color = Country, size = Margin,
                                    alpha = 0.00001)) +
    geom_point(aes(frame = Year)) +
  scale_x_continuous()+
    labs (x= 'Profit (million)', 
          y = ' Revenue (million) ', 
          title = 'Revenue  & Profit 2012-2014',
          legend ="Country",
          size = " ",
          alpha = "")+
  theme(panel.background = element_rect(fill = "white", colour = "grey50"),
        panel.grid.major = element_line(colour = "grey50"),
          plot.margin = margin(0, 0, 3, 2, "cm"))
## Warning: Ignoring unknown aesthetics: frame
ggplotly(Sliders, session = 'knitr') %>% 
animation_opts(1000, easing = "elastic", redraw = FALSE) %>% 
    animation_slider( currentvalue = list(prefix = "YEAR ", font = list(color="violet")))
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

11. Which Country places the most orders online in 2014?

summary(as.factor(Sales12_14$OrderMethod))
##      E-mail         Fax        Mail Sales visit     Special   Telephone 
##        3062        1656        1009        7074         529        5769 
##         Web 
##       68795

11.1 Country places the most orders online in terms of Revenue

Online_Orders2014_byRevenue<- Sales12_14 %>% 
  filter(Year == "2014", OrderMethod == "Web") %>% 
  select(Country, Revenue) %>% 
  na.omit() %>% 
  group_by(Country) %>% 
    summarise(Revenue = sum(Revenue)) %>% 
  arrange(desc(Revenue)) %>% 
  head(Revenue, n=1L)
Online_Orders2014_byRevenue$Revenue <- prettyNum(Online_Orders2014_byRevenue$Revenue, 
                                         big.mark = ",")
kable(Online_Orders2014_byRevenue)
Country Revenue
United States 170,254,299
### The U.S is t he country with most orders online with $170,254,299

11.1 Country places the most orders online in terms of Quantity

Online_Orders2014_byQuan<- Sales12_14 %>% 
  filter(Year == "2014", OrderMethod == "Web") %>% 
  select(Country, Quantity) %>% 
  na.omit() %>% 
  group_by(Country) %>% 
    summarise(Quantity = sum(Quantity)) %>% 
  arrange(desc(Quantity))%>% 
  head(Quantity, n=1L)
Online_Orders2014_byQuan$Quantity <- prettyNum(Online_Orders2014_byQuan$Quantity, 
                                         big.mark = ",")
kable(Online_Orders2014_byQuan)
Country Quantity
United States 2,956,446

The U.S is the country with most orders online with 2959043 of numbers items

Overall, the US is the country places the most order online in 2014

12. Which country has the biggest growth in online orders?

Online_Orders_Growth <- Sales12_14 %>% 
  filter(OrderMethod == "Web") %>% 
  select(Country, Year, Quantity, Revenue) %>% 
  group_by(Country, Year) %>% 
  summarise(Quantity = sum(Quantity), Revenue = sum(Revenue))

12.1 Orderonline growth 2013-2014 by Quantity

Online_Orders_Growth_1 <- Online_Orders_Growth %>% 
  filter(Year != "2012") %>% 
  select(Country, Year, Quantity) %>% 
  spread(Year, Quantity) %>% 
  mutate(difference = `2014`-`2013`) %>% 
  arrange(desc(difference))%>% 
  head(difference, n=1L)
kable(Online_Orders_Growth_1)
Country 2013 2014 difference
Sweden 365828 352089 -13739

12.2 Online Order growth 2013 -2014 by Revenue

Online_Orders_Growth_2 <- Online_Orders_Growth %>% 
  filter(Year != "2012") %>% 
  select(Country, Year, Revenue) %>% 
  spread(Year, Revenue) %>% 
  mutate(difference = `2014`-`2013`) %>% 
  arrange(desc(difference))%>% 
  head(difference, n=1L)
kable(Online_Orders_Growth_2)
Country 2013 2014 difference
Sweden 22681966 20740107 -1941860

Sweden is the country with the smallest decline in online orders

13. Which are the most profitable products?

Profitable_Product <- Sales12_14 %>% 
  select(Product, Quantity, Revenue, GrossProfit) %>% 
  group_by(Product) %>% 
  summarise(Quantity=sum(Quantity), Revenue=sum(Revenue),
            Profit=sum(GrossProfit))

13.1 The most profitable in terms of total profit

Highest_Profit_1 <- Profitable_Product %>% 
  select(Product, Profit) %>% 
  arrange(desc(Profit)) %>% 
head(Profit, n= 10L)
Highest_Profit_1$Profit <- prettyNum(Highest_Profit_1$Profit, big.mark = ",")
kable(Highest_Profit_1)
Product Profit
Hailstorm Titanium Woods Set 45,209,375
Zone 40,899,394
Infinity 40,621,391
Maximus 40,282,326
Star Lite 39,061,918
Inferno 38,145,555
TX 37,711,940
Hailstorm Titanium Irons 35,374,379
Star Gazer 2 33,674,494
Lady Hailstorm Titanium Woods Set 30,449,255

13.2 The most profitable in terms of profit per unit, and cost per unit

Highest_Profit_2 <- Profitable_Product %>%
  na.omit() %>% 
  mutate(Profit_per_unit=Profit/Quantity) %>% 
  select(Product, Profit_per_unit) %>% 
  arrange(desc(Profit_per_unit)) %>% 
  head(Profit, n= 10L)
Highest_Profit_2$Profit_per_unit <- prettyNum(Highest_Profit_2$Profit_per_unit, 
                                              big.mark = ",")
kable(Highest_Profit_2)
Product Profit_per_unit
Lady Hailstorm Titanium Woods Set 663.5993
Hailstorm Titanium Woods Set 563.1532
Lady Hailstorm Steel Woods Set 427.658
Lady Hailstorm Titanium Irons 410.6811
Hailstorm Titanium Irons 401.4615
Hailstorm Steel Woods Set 313.556
Star Gazer 6 302.8579
Star Gazer 3 238.291
Lady Hailstorm Steel Irons 226.8703
Star Dome 226.7223

14. Which are the most profitable product lines?

Profitable_ProductLine <- Sales12_14 %>% 
  na.omit() %>% 
    select(ProductLine, Quantity, Revenue, GrossProfit) %>% 
  group_by(ProductLine) %>% 
  summarise(Quantity=sum(Quantity), Revenue=sum(Revenue),
            Profit=sum(GrossProfit))

14.1 The most profitable product lines in terms of total profit

Highest_Profit_3 <- Profitable_ProductLine%>% 
  select(ProductLine, Profit) %>% 
  arrange(desc(Profit)) 
Highest_Profit_3$Profit <- prettyNum(Highest_Profit_3$Profit, big.mark = ",")
kable(Highest_Profit_3)
ProductLine Profit
Personal Accessories 618,601,957
Camping Equipment 470,295,189
Golf Equipment 281,893,861
Mountaineering Equipment 163,278,857
Outdoor Protection 24,699,875

14.2 The most profitable product lines in terms of profit per unit

Highest_Profit_4 <- Profitable_ProductLine %>%
  na.omit() %>% 
  mutate(Profit_per_unit=Profit/Quantity) %>% 
  select(ProductLine, Profit_per_unit) %>% 
  arrange(desc(Profit_per_unit))
Highest_Profit_4$Profit_per_unit <- prettyNum(Highest_Profit_4$Profit_per_unit, 
                                              big.mark = ",")
kable(Highest_Profit_4)
ProductLine Profit_per_unit
Golf Equipment 70.32727
Personal Accessories 22.63765
Camping Equipment 21.99339
Mountaineering Equipment 16.49422
Outdoor Protection 3.880184

15. Which is the best retailer type?

Best_RetailerType <- Sales12_14 %>% 
  na.omit() %>% 
    select(RetailerType, Quantity, Revenue, GrossProfit) %>% 
  group_by(RetailerType) %>% 
  summarise(Quantity=sum(Quantity), Revenue=sum(Revenue),
            Profit=sum(GrossProfit))

15.1 Best retailer type with the highest profit

HighestProfit_RetailerType_1 <- Best_RetailerType %>% 
  select(RetailerType, Profit) %>% 
  arrange(desc(Profit))

15.2 Best retailer type with the highest number of quantity

HighestProfit_RetailerType_2<- Best_RetailerType %>% 
  select(RetailerType, Quantity) %>% 
  arrange(desc(Quantity))

15.3 Best retailer type with the highest revenue

HighestProfit_RetailerType_3<- Best_RetailerType %>% 
  select(RetailerType, Revenue) %>% 
  arrange(desc(Revenue))
join1 <- inner_join(HighestProfit_RetailerType_1, HighestProfit_RetailerType_2,  by = "RetailerType")
  Best_Retailer_Type <- inner_join(join1, HighestProfit_RetailerType_3, by = "RetailerType")
  kable(Best_Retailer_Type )
RetailerType Profit Quantity Revenue
Outdoors Shop 511033204 25905357 1267370732
Sports Store 399994822 16753737 969880760
Department Store 274906813 12878704 662445711
Golf Shop 193519777 4392068 410870169
Eyewear Store 74140318 2701365 171718155
Warehouse Store 64956723 3373039 192336169
Direct Marketing 22685977 1899138 54367078
Equipment Rental Store 17532106 1079436 43434191

The best retailer type is Outdoor Shop.