[英]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.