繁体   English   中英

将误差线添加到分组的R绘图条形图中

[英]Adding error bars to a grouped R plotly bar chart

我有要使用带有y误差线的R plotly条形图进行绘图的数据。 数据由两组组成,每组都具有三种类型的度量值:

set.seed(1)
df <- data.frame(group = c(rep("A",3),rep("B",3)),
                 type = rep(letters[1:3],2),
                 mean.proportion = runif(6,0,1),
                 se.proportion = runif(6,0.01),
                 stringsAsFactors = F)
df$group <- factor(df$group)
df$type <- factor(df$type)

如果我仅使用以下方法绘制没有错误线的线:

plotly::plot_ly(x=df$type,y=df$mean.proportion,type='bar',color=df$group,showlegend=T) %>%
  plotly::layout(xaxis=list(title=NA),yaxis=list(title="Proportion"),barmode='group')

结果很好:

在此处输入图片说明

但是,当我尝试使用以下方法添加y错误栏时:

plotly::plot_ly(x=df$type,y=df$mean.proportion,type='bar',color=df$group,showlegend=T) %>%
  plotly::layout(xaxis=list(title=NA),yaxis=list(title="Proportion"),barmode='group') %>%
  plotly::add_trace(error_y=list(array=df$se.proportion))

搞砸了-胸罩加倍: 在此处输入图片说明

任何想法?

尝试在第一条语句中绘制它们:

plotly::plot_ly(x=df$type,y=df$mean.proportion,type='bar',color=df$group,showlegend=T, error_y=list(array=df$se.proportion)) %>%
  plotly::layout(xaxis=list(title=NA),yaxis=list(title="Proportion"),barmode='group')

输出:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM