0
以下のコードを使用して、棒グラフを表示します。積算棒グラフの頂点に計算値を表示する方法
myDF <- structure(list(Group = structure(1:3, .Label = c("2017-04-02",
"2017-04-09", "2017-04-16"), class = "factor"), Passive = c(4,
1, 0), Promoter = c(12, 1, 4), Detractors = c(0, 0, 0)), .Names = c("Group",
"Passive", "Promoter", "Detractors"), row.names = c(NA, -3L), class = "data.frame")
x <- list(
title = ""
)
y <- list(
title = "Count"
)
p <- plot_ly(myDF, x = ~Group)
if ("Detractors" %in% colnames(myDF[-1])){
p <- add_trace(p, y = ~`Detractors`, name = 'Detractors', type = 'bar',
marker = list(color = '#D52728')) #red
}
if ("Passive" %in% colnames(myDF[-1])){
p <- add_trace(p, y = ~`Passive`, name = 'Passive', type = 'bar',
marker = list(color = '#1F78B4')) #orange
}
if ("Promoter" %in% colnames(myDF[-1])){
p <- add_trace(p, y = ~`Promoter`, name = 'Promoter', type = 'bar',
marker = list(color = '#2BA02D')) #green
}
p <- layout(p, xaxis = x, yaxis = y, barmode = 'stack', legend = list(orientation = 'h'), showlegend=T)
p
私は、各バーの上にネットプロモータースコアを示したいと思います。 NPSの計算に使用する計算式は、 (Number of Promoters — Number of Detractors)/(Number of Respondents) x 100
です。 最初のバーの場合は((12 - 0)/16) * 100 = 75
となります。私はNPS: 75
を最初のバーの上に表示したいと思います。同様に、2番目と3番目のバーの場合、上の数字はそれぞれ(1-0)/2*100 = 50
と(4-0)/4*100 = 100
になります。私は今後数週間データを取得する予定ですので、今後毎週データの棒が表示されます。棒の上にこの計算値を表示する方法はありますか?あなたはx
値があなたの日付あるごlayout
にannotation
秒を追加することができ