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="")


 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值