[英]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))
任何想法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.