当前位置:   article > 正文

fourkk

fourkk

data(faithful)
head(faithful)
#绘制eruptions的直方图,添加核密度曲线和扰动图
str(faithful)
attach(faithful)
summary(faithful)#查看eruption的最大值
hist(eruptions,xlab="喷发持续时间",ylim =c(0,100) )
hist(eruptions,freq=F,prob=T,breaks = 25,col='deepskyblue',xlab="喷发持续时间",ylab = "密度")
lines(density(eruptions))#添加核密度曲线
rug(jitter(eruptions))
#绘制eruption和waiting的叠加直方图
hist(faithful$waiting,prob=T,breaks = 25,xlab = "指标值",ylab="密度",col="deepskyblue")
hist(faithful$eruptions,prob=T,breaks = 25,xlab = "",ylab="",col="red2",density=60)
#做不出来,要进行标准化
data(faithful)
adf=scale(faithful)
sdf <- as.data.frame(adf)
hist(sdf$eruptions,breaks=20,prob=TRUE,col="blue",xlab="value",ylab="density",main="")
hist(sdf$waiting,  breaks=20,prob=TRUE,col="green",        xlab="value",ylab="density",main="",add=TRUE)
legend("topright", legend=c("Eruptions", " Waiting "), fill=c("green","blue"))
#绘制eruption和waiting的核密度比较图
library(reshape2);library(gridExtra);library(ggplot2)
ggplot(faithful, aes(x=eruptions, fill="eruptions")) +
  geom_density(alpha=0.3) +
  geom_density(aes(x=waiting, fill="waiting"), alpha=0.5) +
  scale_fill_manual(values=c("eruptions"="green", "waiting"="red"), guide=guide_legend(title=NULL)) +
  labs(x="value", y="density") +
  theme_minimal()
#绘制eruption和waiting的箱线图和小提琴图
#箱线图
boxplot(faithful,xlab="指标",ylab="指标值")
#小提琴图(vioplot)
library(vioplot)
vioplot(faithful,xlab="指标","指标值")
#绘制eruption和waiting的茎叶图
library(aplpack)
stem.leaf(faithful$eruptions)
stem.leaf(faithful$waiting)
##绘制eruption和waiting的点图和带状图
#点图
dotchart(faithful$eruptions,groups = faithful$waiting)
#带状图
data(faithful)
adf=scale(faithful)
sdf <- as.data.frame(adf)
stripchart(sdf$eruptions,method = "overplot",at=1.35,pch = "A",col="blue3")
stripchart(sdf$waiting,method = "jitter",at=1.16,pch = "P",col = "Orange",add = T)
##绘制eruption和waiting的分布概要图
library(aplpack)
plotsummary(faithful,types=c("stripes","ecdf","density","boxplot"),y.sizes=4:1,design="chessboard",mycols="RB",main="")


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/131935
推荐阅读
相关标签
  

闽ICP备14008679号