본문 바로가기
R

stat_summary

by jangpiano 2020. 9. 9.
반응형


> msleep2<-msleep%>%filter(!is.na(vore))

> ggplot(data=msleep2,aes(x=vore,y=sleep_total))+geom_boxplot()


<Add another representative's value> 


> ggplot(data=msleep2,aes(x=vore,y=sleep_total))+geom_boxplot()+stat_summary(fun="mean",geom="point")

> ggplot(data=msleep2,aes(x=vore,y=sleep_total))+geom_boxplot()+stat_summary(fun="mean",geom="point",shape=22,fill="red")

> ggplot(data=msleep2,aes(x=vore,y=sleep_total))+geom_boxplot()+stat_summary(fun="median",geom="point",shape=21,fill="red",size=3)

> ggplot(data=msleep2,aes(x=vore,y=sleep_total,group=1))+geom_point()+stat_summary(fun="median",geom="line",colour="red")

> ggplot(data=msleep2,aes(x=vore,y=sleep_total))+geom_point()+stat_summary(fun="median",geom="point",shape=21,fill="red",size=3)

> ggplot(data=msleep2,aes(x=vore,y=sleep_total,group=1))+geom_point()+stat_summary(fun="mean",geom="point",fill="blue",size=3,shape=21)+stat_summary(fun="median",geom="line",colour="red")

> ggplot(data=msleep2,aes(x=vore,y=sleep_total))+geom_point()+stat_summary(fun="median",geom="crossbar",colour="red")



> msleep<-msleep%>%mutate(sleep_rem_d=sleep_rem-1.87541)

> msleep2<-msleep%>%mutate(rem_rank=ifelse(sleep_rem_d<=0,"little","much"))%>%group_by(vore,rem_rank)

> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank))+geom_bar(stat="identity")


> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank))+geom_bar(stat="identity")+stat_summary(fun=mean,geom="point")

> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank))+geom_bar(stat="identity")+stat_summary(fun=mean,geom="crossbar")

> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank,group=rem_rank))+geom_bar(stat="identity")+stat_summary(fun=mean,geom="line")

> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank,group=rem_rank))+geom_bar(stat="identity")+stat_summary(fun=mean,geom="point")+stat_summary(fun=mean,fun.max=function(x)mean(x)+sd(x),fun.min=function(x)mean(x)-sd(x),geom="errorbar")







반응형