本文的目标是分析和确定当前零售销售的趋势和模式,并确定哪个市场部门处于亏损状态,哪个部门正在赚取巨额利润。
每个行业都提供销售的折扣,但是,他们的折扣促销活动,能否带来更大的利润呢?
让我们开始吧!
加载软件包
rm(list=ls())
library(ggplot2)
library(tidyverse)
读取数据集
df <- read.csv("SampleSuperstore.csv")
str(df)
## 'data.frame': 9994 obs. of 13 variables:
## $ Ship.Mode : Factor w/ 4 levels "First Class",..: 3 3 3 4 4 4 4 4 4 4 ...
## $ Segment : Factor w/ 3 levels "Consumer","Corporate",..: 1 1 2 1 1 1 1 1 1 1 ...
## $ Country : Factor w/ 1 level "United States": 1 1 1 1 1 1 1 1 1 1 ...
## $ City : Factor w/ 531 levels "Aberdeen","Abilene",..: 195 195 267 154 154 267 267 267 267 267 ...
## $ State : Factor w/ 49 levels "Alabama","Arizona",..: 16 16 4 9 9 4 4 4 4 4 ...
## $ Postal.Code : int 42420 42420 90036 33311 33311 90032 90032 90032 90032 90032 ...
## $ Region : Factor w/ 4 levels "Central","East",..: 3 3 4 3 3 4 4 4 4 4 ...
## $ Category : Factor w/ 3 levels "Furniture","Office Supplies",..: 1 1 2 1 2 1 2 3 2 2 ...
## $ Sub.Category: Factor w/ 17 levels "Accessories",..: 5 6 11 17 15 10 3 14 4 2 ...
## $ Sales : num 262 731.9 14.6 957.6 22.4 ...
## $ Quantity : int 2 3 2 5 2 7 4 6 3 5 ...
## $ Discount : num 0 0 0 0.45 0.2 0 0 0.2 0.2 0 ...
## $ Profit : num 41.91 219.58 6.87 -383.03 2.52 ...
summary(df)
## Ship.Mode Segment Country
## First Class :1538 Consumer :5191 United States:9994
## Same Day : 543 Corporate :3020
## Second Class :1945 Home Office:1783
## Standard Class:5968
##
##
##
## City State Postal.Code Region
## New York City: 915 California :2001 Min. : 1040 Central:2323
## Los Angeles : 747 New York :1128 1st Qu.:23223 East :2848
## Philadelphia : 537 Texas : 985 Median :56431 South :1620
## San Francisco: 510 Pennsylvania: 587 Mean :55190 West :3203
## Seattle : 428 Washington : 506 3rd Qu.:90008
## Houston : 377 Illinois : 492 Max. :99301
## (Other) :6480 (Other) :4295
## Category Sub.Category Sales Quantity
## Furniture :2121 Binders :1523 Min. : 0.444 Min. : 1.00
## Office Supplies:6026 Paper :1370 1st Qu.: 17.280 1st Qu.: 2.00
## Technology :1847 Furnishings: 957 Median : 54.490 Median : 3.00
## Phones : 889 Mean : 229.858 Mean : 3.79
## Storage : 846 3rd Qu.: 209.940 3rd Qu.: 5.00
## Art : 796 Max. :22638.480 Max. :14.00
## (Other) :3613
## Discount Profit
## Min. :0.0000 Min. :-6599.978
## 1st Qu.:0.0000 1st Qu.: 1.729
## Median :0.2000 Median : 8.666
## Mean :0.1562 Mean : 28.657
## 3rd Qu.:0.2000 3rd Qu.: 29.364
## Max. :0.8000 Max. : 8399.976
##
数据准备和清理
检查异常:
#any null values?
is.null(df)
## [1] FALSE
#any duplicacy?
dfnew <- df %>% distinct() ##yes, duplicates were removed
我们看到 Sales 功能中存在异常值,即异常增长。让我们用销售平均值代替它。
maxSales <- max(dfnew$Sales)
dfnew$Sales <- replace(dfnew$Sales, dfnew$Sales==maxSales,mean(dfnew$Sales))
删除国家/地区和邮政编码功能
dfnew <- dfnew %>% select(-c(Country, Postal.Code))
可视化
让我们分析清理后的数据
销售与数量
在下图中,我们看到以下模式,即大多数销售都是由标准舱触发的。
ggplot(data = dfnew, aes(x = Quantity, y = Sales, fill = Ship.Mode) )+ geom_bar(stat = "identity")
销售额与利润
因此,显然,我们看到标准舱得了更多的利润/损失。
ggplot(data = dfnew, aes(x = Sales, y = Profit, color = Ship.Mode)) + geom_point()
销售与折扣
让我们看看如果提供折扣,销售会受到怎样的影响。
ggplot() + geom_point(data = dfnew, aes(x = Discount, y = Sales, color = Ship.Mode))
从上图可以明显看出,折扣会吸引更多的销售。但是,折扣主要吸引标准舱的货物。
利润与折扣
让我们看看如果兑换了折扣,是否触发了利润。
ggplot() + geom_bar(data = dfnew, aes(x = Discount, y = Profit, fill = Ship.Mode), stat = "identity")
我们看到,提供和兑换的折扣越多,细分市场获得的利润就越少。 没有折扣的产品显示出很高的利润范围,但随着折扣范围的增加,我们只会看到越来越多的损失,几乎没有任何利润。
让我们看看其他细分市场是否是这种情况
ggplot() + geom_bar(data = dfnew, aes(x = Sub.Category, y = Profit, fill = Region), stat = "identity") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
我们看到,binders主要销量集中在中部地区,Machines和Tables则遭受了更多的损失。
现在
ggplot() + geom_bar(data = dfnew, aes(x = Category, y = Sales, fill = Region), stat = "identity") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
工艺类别的销售额有所增加,然后是家具和办公用品。主要来自西部和东部地区
ggplot() + geom_bar(data = dfnew, aes(x = Category, y = Profit, fill = Region), stat = "identity") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
家具类别的损失大于工艺和办公用品类别的损失。
销售额从低到高不等,利润也是如此。
ggplot() + geom_point(data = dfnew, aes(x = Sales, y = Profit, color = Category))
我们现在从上面的图表中可以看出,无论它们如何排列,每个类别的销售与利润比率都是相同的。
结论
如果推出更多的折扣活动,当天发货可以触发销售/利润。 折扣应以销售额为基础,不应增加特定范围,否则销售额低的不必要的产品可能会遭受巨大损失,以加强这些被削弱的行业领域。 办公用品和家具行业在中部地区似乎并不繁荣,可做进一步的调查。