我想使用带有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))
有什么主意吗?