w <- read.csv(“D://小学期/可视化数据.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 n e w . d a t e < − p a s t e ( s u b s t r ( w new.date <- paste(substr(w new.date<−paste(substr(w日期,6,7),substr(w 日 期 , 9 , 10 ) , s e p = " / " ) / / 将 日 期 进 行 规 范 化 h e a d ( w ) b a r p l o t ( h e i g h t = w 日期,9,10),sep = "/") //将日期进行规范化 head(w) barplot(height = w 日期,9,10),sep="/")//将日期进行规范化head(w)barplot(height=w新增用户, names.arg = wKaTeX parse error: Expected 'EOF', got '#' at position 222: …lor_FFFFFF,t_70#̲pic_center) #双指…活跃用户~wKaTeX parse error: Expected 'EOF', got '#' at position 60: …户 vs 新增用户散点图") #̲添加线性拟合直线 abline…活跃用户~w$新增用户),col=“blue”,lwd=2,lty=2) #还可以进行哪些双指标分析?通过分析双指标,得出相对应的结论。
#三指标数据可视化 plot(w 活 跃 用 户 w 活跃用户~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 p r e , d a t a pre,data pre,datanow)), 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 n o w − d a t a now-data now−datapre)/dataKaTeX parse error: Expected 'EOF', got '#' at position 5: pre #̲#环比增长 = (now[t]…now)/data n o w [ 1 : ( l e n g t h ( d a t a now[1:(length(data now[1:(length(datanow)-1)]) a<-200; b<-370; lines(c(2,5,8,11,14,17,20), asame.pre.growth+b,type=“b”,lwd=2) lines(c(2,5,8,11,14,17,20), aring.growth+b,type=“b”,lwd=2,col=“blue”)
##在同比和环比曲线上添加文字 j <- 1 for(i in 1:length(data[,1])){ #在bar上画数值 text(3i-1, asame.pre.growth[i]+b-5, paste(round(same.pre.growth[i]10000)/100, “%”,sep="")); j <- j+1; text(3i-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 p r e [ i ] + 10 , d a t a pre[i]+10, data pre[i]+10,datapre[i], col=“deepskyblue4”); j < j+1 #组内间距为1 text(j+1.5,data n o w [ i ] + 10 , d a t a now[i]+10, data now[i]+10,datanow[i], col=“deepskyblue4”); j <- j+3 #组外间距为3 }
logindata<- read.csv(“D://小学期/abalone.csv”, header = F, as.is=T) data.names <- c(“Gender”,“Length”,“Diameter”,“Height”,“Wholeweight”,“Shuckedweight”,“Visceraweight”,“Shellweight”,“Rings” ) colnames(logindata) <- data.names 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:11,1:11], lower = “ellipse”, upper = “number”, tl.pos=“lt”,diag=“u”)
funnel <- read.csv(“D://小学期/新手教程路径留存人数统计.csv”, header = T, fileEncoding = “UTF-8”) 查看funnel数据集 funnel 绘制漏斗图 对数据进行降序排序 funnel_order <- funnel[order(funnel 用 户 数 ) , ] 绘 制 漏 斗 图 b a r p l o t ( f u n n e l o r d e r 用户数),] 绘制漏斗图 barplot(funnel_order 用户数),]绘制漏斗图barplot(funnelorder用户数,horiz = T,axes=F,border=F,space=0.5, col=“steelblue1”,xlim=c(-700,700), main=“新手教程关键路径漏斗图”) barplot(-funnel_order 用 户 数 , h o r i z = T , a d d = T , b o r d e r = F , s p a c e = 0.5 , a x e s = F , c o l = " s t e e l b l u e 1 " ) 增 加 步 骤 名 称 t e x t ( x = r e p ( − 600 , 6 ) , y = s e q ( 1 , 8.5 , l e n g t h . o u t = 6 ) , l a b e l s = f u n n e l o r d e r 用户数,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 用户数,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=funnelorder事件行为,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 / m a x ( f u n n e l o r d e r 用户数*100/max(funnel_order 用户数∗100/max(funnelorder用户数),2),"%"), cex=0.8,font=3,col=“violetred3”) 增加上一步的转化率 text(x=rep(max(funnel 用 户 数 ) , 6 ) , y = s e q ( 2 , 7.5 , l e n g t h . o u t = 5 ) , l a b e l s = p a s t e 0 ( r o u n d ( f u n n e l o r d e r 用户数),6),y=seq(2,7.5,length.out = 5), labels=paste0(round(funnel_order 用户数),6),y=seq(2,7.5,length.out=5),labels=paste0(round(funnelorder用户数[1:5]/funnel_order$用户数[2:6]*100,2),"%"), cex=0.8,font=4,col=“red3”)
