文章目录
一、散点图二、散点图三、趋势分析四、相关性分析
一、散点图
代码如下(示例):
#游戏数据可视化
# 绘制散点图
w
<- read
.csv("可视化数据.csv", header
= F
,
as
.is
=T
)
str(w
)
head(w
)
data
.names
<- c("日期","活跃用户","新增用户","付费率",
"付费用户","首次付费用户","ARPPU","ARPU")
colnames(w
) <- data
.names
str(w
)
head(w
)
#单指标数据可视化
summary(w
)
w$new
.date
<- paste(substr(w$日期
,6,7),substr(w$日期
,9,10),sep
= "/")
head(w
)
barplot(height
= w$新增用户
, names
.arg
= w$new
.date
)
#还可以进行哪些单指标分析?通过分析单指标,得出相对应的结论。
二、散点图
#双指标数据可视化
plot(w$活跃用户
~w$新增用户
,col
="violetred2",pch
=16,
main
="活跃用户 vs 新增用户散点图")
#添加线性拟合直线
abline(lm(w$活跃用户
~w$新增用户
),col
="blue",lwd
=2,lty
=2)
#还可以进行哪些双指标分析?通过分析双指标,得出相对应的结论。
#三指标数据可视化
plot(w$活跃用户
~w$新增用户
,col
="violetred2",pch
=16,
cex
=w$付费率
,
main
="活跃用户 vs 新增用户气泡图")
三、趋势分析
#同比、环比
data
<- data
.frame(pre
=c(113,134,123,145,137,196,187),
now
=c(129,122,134,149,146,215,208));
ylim
.max
<- 550
col
= c("azure4","brown4")
##将主副标题放到barplot函数里,进行设置
##font
=3,表示字体为“斜体”
##cex
=1.5,表示字体放大
1.5倍
barplot(as
.matrix(rbind( data$pre
,data$now
)),
beside
=TRUE
,ylim
=c(0,ylim
.max
),col
=col
,axes
=F
,
main
=list( "本周pv趋势分析图",cex
=1.5,col
="red",font
=3),
sub
=paste("范围:2020.09.28--2020.10.04","\n","网站板块:军事科技"),
ylab
="网站日页面浏览量pv"
)
axis(2)
##画图例
text
.legend
= c("上周pv","本周pv","pv同比增长","pv环比增长")
col2
<- c("black","blue")
legend("topleft",pch
=c(15,15,16,16), legend
=text
.legend
,cex
=0.8,col
=c(col
,col2
),bty
="n",
horiz
=F
)
##画刻度标记
text
.x
<- c("周一","周二","周三","周四","周五","周六","周日")
axis(side
=1, c(2,5,8,11,14,17,20), labels
=text
.x
,tick
=TRUE
, cex
.axis
=0.75)
axis(4,at
=seq(from
=250,length
.out
=7,by
=40),labels
=c("-60%","-40%","-20%","0","20%","40%","60%"))
##添加“同比增长曲线”和“环比增长曲线”
##同比增长
= (now
[t
]-pre
[t
])/pre
[t
]
same
.pre
.growth
<- (data$now
-data$pre
)/data$pre
##环比增长
= (now
[t
]-now
[t
-1])/now
[t
-1]
ring
.growth
<- c(NA
,diff(data$now
)/data$now
[1:(length(data$now
)-1)])
a
<-200; b
<-370;
lines(c(2,5,8,11,14,17,20), a
*same
.pre
.growth
+b
,type
="b",lwd
=2)
lines(c(2,5,8,11,14,17,20), a
*ring
.growth
+b
,type
="b",lwd
=2,col
="blue")
##在同比和环比曲线上添加文字
j
<- 1
for(i in
1:length(data
[,1])){ #在bar上画数值
text(3*i
-1, a
*same
.pre
.growth
[i
]+b
-5, paste(round(same
.pre
.growth
[i
]*10000)/100,
"%",sep
=""));
j
<- j
+1;
text(3*i
-1, a
*ring
.growth
[i
]+b
+5, paste(round(ring
.growth
[i
]*10000)/100,
"%",sep
=""),col
="blue");
j
<- j
+2;
}
##在pv柱状图上添加文字
j
<- 1
for(i in
1:length(data
[,1])){
text(j
+0.5,data$pre
[i
]+10, data$pre
[i
], col
="deepskyblue4");
j
< j
+1 #组内间距为
1
text(j
+1.5,data$now
[i
]+10, data$now
[i
], col
="deepskyblue4");
j
<- j
+3 #组外间距为
3
}
四、相关性分析
logindata
<- read
.csv("logindatatest.csv",
header
= T
, fileEncoding
= "UTF-8")
logindata
<- read
.csv("abalone.csv",
header
= T
, fileEncoding
= "UTF-8")
str(logindata
)
nrow(logindata
)
dim(logindata
)
library(caret
)
dmy
<-dummyVars(~.,data
=logindata
)
dmyTsrf
<-data
.frame(predict(dmy
,newdata
=logindata
))
dim(dmyTsrf
)
str(dmyTsrf
)
log
.cor
<- cor(dmyTsrf
, use
="pairwise.complete.obs")
#install.packages("corrplot")
library(corrplot
)
corrplot
.mixed(log
.cor
[1:9,1:9], lower
= "ellipse",
upper
= "number",
tl
.pos
="lt",diag
="u")
# 漏斗分析
# 导入新手教程关键路径用户数
funnel
<- read
.csv("新手教程路径留存人数统计.csv",
header
= T
, fileEncoding
= "UTF-8")
funnel
<- read
.csv("glass.csv",
header
= T
, fileEncoding
= "UTF-8")
# 查看funnel数据集
funnel
# 绘制漏斗图
# 对数据进行降序排序
funnel_order
<- funnel
[order(funnel$用户数
),]
# 绘制漏斗图
barplot(funnel_order$用户数
,horiz
= T
,axes
=F
,border
=F
,space
=0.5,
col
="steelblue1",xlim
=c(-700,700),
main
="新手教程关键路径漏斗图")
barplot(-funnel_order$用户数
,horiz
=T
,add
=T
,border
=F
,space
=0.5,
axes
=F
,col
="steelblue1")
# 增加步骤名称
text(x
=rep(-600,6),y
=seq(1,8.5,length
.out
= 6),
labels
=funnel_order$事件行为
,cex
=0.8,font
=3,col
="black")
# 增加总体的转化率
text(x
=rep(0,6),y
=seq(1,8.5,length
.out
= 6),
labels
=paste0(round(funnel_order$用户数
*100/max(funnel_order$用户数
),2),"%"),
cex
=0.8,font
=3,col
="violetred3")
# 增加上一步的转化率
text(x
=rep(max(funnel$用户数
),6),y
=seq(2,7.5,length
.out
= 5),
labels
=paste0(round(funnel_order$用户数
[1:5]/funnel_order$用户数
[2:6]*100,2),"%"),
cex
=0.8,font
=4,col
="red3")