R语言 堆叠可视化/可视化对比分析简单学习案例(R语言&大数据分析qq群 456726635 欢迎讨论交流)
本文进行了销售同比的堆叠可视化分析,使用R语言实现了简单案例,跟大家共同学习。点击链接加入群【R语言&大数据分析】:https://jq.qq.com/?_wv=1027&k=4BQLEWp,R语言&大数据分析qq群 456726635 欢迎讨论交流
library(data.table)
chinesemonth=paste(a,b,sep = "")
df<-fread("D:/资讯工作资料/bartestdata/saledata.csv",header=T)
entities<-unique(df$entityno) #所有店铺
#单店铺数据
entitydata <- data.table(subset(df,grepl(entities[1],df$entityno,ignore.case = F)))
entitydata <- entitydata[order(entitydata[,1],decreasing=F),]
entitydata
mydate<-unique(entitydata$date)
currentsale<-vector() #今年销售
lastsale<-vector() #去年销售
currentdisc<-vector() #今年折扣
lastdisc<-vector() #去年折扣
for(i in 1:length(mydate))
{
slic<-data.table(subset(entitydata,grepl(mydate[i],entitydata$date,ignore.case = F)))
currentsale[i]<-sum(as.numeric(slic$sale))
lastsale[i]<-sum(as.numeric(slic$lastsale))
currentdisc[i]<-sum(as.numeric(slic$sale))/sum(as.numeric(slic$price))
lastdisc[i]<-sum(as.numeric(slic$lastsale))/sum(as.numeric(slic$lastprice))
}
nf <-layout(matrix(c(1,2,3,4,5,6,7,8,9,10,11,12,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14), 3, 12, byrow = T),heights=c(1.5,1,1))
layout.show(nf)
#par(mar = c(3,0,1,1))
par(mar = c(3,1,0,1))
for(i in 1:12)
{
#barplot(yhist$counts, axes = FALSE, xlim = c(0, top), space = 0, horiz = TRUE)
if(i %% 2 == 0)
{
par(mar = c(3,0,0,1))
barplot(c(1, 0.6, 0.4), horiz = T, xlim = 0:1)
}
else
{
par(mar = c(3,1,0,0))
barplot(c(1, 0.6, 0.4), horiz = T, xlim = 1:0)
}
}
par(mar = c(3,3,0,1))
qq=data.table(currentdisc)
ww=data.table(lastdisc)
discdata=data.table(ww,qq)
matplot(discdata,type="o",pch=15:16)
#legend("topright",pch=16:17,col=2:3,legend = names(discdata))
qq1=data.table(currentsale)
ww1=data.table(lastsale)
discdata=data.table(ww1,qq1)
matplot(discdata,type="o",pch=15:16)