R语言中循环、图形 10-17周六

3 篇文章 0 订阅

for:

for(i in 1:10) 
print('hello')

i<-10
while (i>0) {print('hello');i<-i-1}

 ifelse (score>0.5,print('passed'),print('Failed)


options(digits=3)
attach(mtcars)
aggdata<-aggregate(mtcars,by=list(cyl,gear),Fun=mean,na.rm=TRUE)
 

#基本条形图

barplot(counts,main='main',ylab='y',xlab='x')


#拼图求均值

states<-data.frame(state.region,state.x77)
means<-aggregate(states$Illiter,by=list(state.region),FUN=mean)

counts<-table(data$T1)


饼图

par(mfrow=c(2,2))
slices<-c(10,12,4,16,8)
lbls<-c('A','B','C','D','E')
pie(slices,labels=lbls,main='ttt')

pct<-round(slices/sum(slices)*100)
lbls2<-paste(lbls,'',pct,'%',sep='')
pie(slices,labels=lsls,col=rainbow(lengtn(lbls2)),main='tt')

#rainbow(length(lbls2))   代表提供了lsls2长度的不同颜色

直方图

par(mfrow=c(2,2))
hist(mtcars$mpg)

hist(mtcars$mpg,breaks=12,col='red',xlab='mile',main='tt')
#按等分划分

hist(mtcars$mpg,freq=FALSE,breaks=12,col='red',
xlab='mile',main='t',rug(jitter(mtcars$mpg)),lines(density(mtcars$mpg),col='blue,lwd=2)

#添加轴虚线

核密度图、箱线图

par(mfrow=c(2,1))
d<-density(mtcars$mpg)
boxplot(mtcars$mpg,main='tt',ylab='dd')

boxplot(mpg~cyl,data=mtcars,main='tt',xlab='cyl',ylab='mpg')

#分类箱线图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值