R2-30第十次作业 综合运用

土貉 2018-01-09 13:59:41 阅读: 1167

summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,                      conf.interval=.95, .drop=TRUE) {

    library(plyr)

   

    # 计算长度

    length2 <- function (x, na.rm=FALSE) {

        if (na.rm) sum(!is.na(x))

        else       length(x)

    }

   

    # groupvars 为组,计算每组的长度,均值,以及标准差

    # ddply 就是 dplyr 中的 group_by + summarise

    datac <- ddply(data, groupvars, .drop=.drop,

                   .fun = function(xx, col) {

                       c(N    = length2(xx[[col]], na.rm=na.rm),

                         mean = mean   (xx[[col]], na.rm=na.rm),

                         sd   = sd     (xx[[col]], na.rm=na.rm)

                       )

                   },

                   measurevar

    )

   

    # 重命名 

    datac <- plyr::rename(datac, c("mean" = measurevar))

   

    # 计算标准偏差

    datac$se <- datac$sd / sqrt(datac$N)  # Calculate standard error of the mean

   

    # Confidence interval multiplier for standard error

    # Calculate t-statistic for confidence interval:

    # e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1

    # 计算置信区间

    ciMult <- qt(conf.interval/2 + .5, datac$N-1)

    datac$ci <- datac$se * ciMult

   

    return(datac)

}

 

tg<-ToothGrowth

tgc<-summarySE(tg,measurevar = "len",groupvars = c("supp","dose"))

 

library("ggplot2")
pd<-position_dodge(0.1)
 
ggplot(tgc,aes(x=dose,y=len,colour=supp,group=supp))+geom_line(position = pd)+geom_errorbar(aes(ymin=len-sd,ymax=len+sd),colour="black",width=0.1,position = pd)+geom_point(position = pd,size=2,shape=21,fill="white")+xlab("Dose(mg)")+ylab("Tooth length")+scale_colour_hue(name="Supplement type",breaks=c("OJ","VC"),labels=c("Orange juice","Ascorbic acid"),l=40)+ggtitle("R2-30 Mean±Sd")+expand_limits(y=0)+scale_y_continuous(breaks = 0:20*4)+theme_bw()+theme(legend.justification = c(1,0),legend.position = c(1,0))
 

01.png

 options(scipen = 100)
library("ggplot2")
theme_set(theme_bw())
 data("midwest",package = "ggplot2")
ggplot(midwest,aes(x=area,y=poptotal))+geom_point(aes(col=state,size=popdensity))+geom_smooth(method="loess",se=T)+xlim(c(0,0.1))+ylim(c(0,500000))+labs(subtitle="Area VS population",x="Area",y="Population",title="R2-30",caption="Source:midwest")

02.png


library("ggplot2")

datar10<-read.csv(file.choose())

datar101<-as.matrix(datar10[,2:20])

row.names(datar101)<-datar10[,1]

 

heatmap(datar101,Rowv=NA,Colv=NA,scale="column",margins=c(5,10),col=colorRampPalette(c("white", "blue"))(256),main="R2-30")

 


03.png



 
邀请讨论

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
{{item.nick_name}} 受邀请回答 {{item.create_time}}
{{item.refer_comment.nick_name}} {{item.refer_comment.create_time}}

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
切换到完整回复 发送回复
赞({{item.count_zan}}) 踩({{item.count_cai}}) 删除 回复 关闭
科研狗©2015-2024 科研好助手,京ICP备20005780号-1 建议意见

服务热线

178 0020 3020

微信服务号