簡體   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