美文网首页
R画带误差线的分组柱形图

R画带误差线的分组柱形图

作者: 纵纵纵小鸮 | 来源:发表于2022-10-22 22:46 被阅读0次

代码

library(reshape2)

library(ggplot2)

mydata<-read.csv("input_total10.13.csv", header=T)

data<-melt(mydata)

head(data)

ebtop<-function(x){

  return(mean(x)+sd(x)/sqrt(length(x)))

}

ebbottom<-function(x){

  return(mean(x)-sd(x)/sqrt(length(x)))

}

ggplot(data=data,aes(x=data$group,y=value,fill=data$variable))+

  stat_summary(geom = "bar",fun = "mean",

              position = position_dodge(0.9))+

  stat_summary(geom = "errorbar",

              fun.min = ebbottom,

              fun.max = ebtop,

              position = position_dodge(0.9),

              width=0.2)+

  theme_classic()+

  theme(panel.grid = element_blank())+

  scale_fill_manual(values = c("#81B29A","#F2CC8F","#3D405B","#E07A5F"),

                    name="TTL")+

  labs(x="XXXXX",y="YYYYY")   ##设置颜色和坐标轴

数据:

结果图:

代码来源于:https://cloud.tencent.com/developer/article/1917844

相关文章

网友评论

      本文标题:R画带误差线的分组柱形图

      本文链接:https://www.haomeiwen.com/subject/gwjwzrtx.html