Stacked Barchart with total amount of bars text
オープン
まだ誰も着手していません。
- 主要言語
- R
- スター
- 2.7k
- フォーク
- 641
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Problem: I have a stacked barchart. Above each of the stacked bars I want to have a total number (i.e. the sum of the two bars - here: total). I tried to take usage of add_text but it did not work out as expected. Any suggestions what to change?
Remark: I do not want to cast the data.table object. The target frame on which the visualizations shall be made is new_frame.
Many thanks
Brief description of the problem
library(data.table)
library(plotly)
Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 23)
LA_Zoo <- c(12, 18, 29)
data <- data.table(Animals, SF_Zoo, LA_Zoo)
new_frame <- data.table::melt(data, id.vars='Animals')
new_frame[, total := sum(value), by = Animals]
plot_ly(new_frame, x = ~Animals,
y = ~value,
type = 'bar',
name = ~variable,
text = ~paste(variable, value, total),
textposition = 'auto',
# insidetextfont = list(size = 10, color = 'black'),
hovertext = ~paste(
"<b>Hover text works IN/OUT</b><br>"),
hoverinfo = 'text',
hoverlabel = list(align = "left"),
showlegend = TRUE) %>%
add_text(
visible = "legendonly",
x= ~Animals,
y = ~total,
# showlegend = TRUE,
name = "Titel",
cliponaxis = FALSE,
textfont = list(size = 10)
)%>%
layout(yaxis = list(title = 'Count'), barmode = 'stack')

コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
data.table::melt、plot_ly、add_textを使用した再現可能なRの例から始め、次に積み上げ棒グラフのトレースが合計ラベルをどのように配置するかを調べます。data.tableオブジェクトをキャストせずに、new_frame上の各積み上げ棒の上に合計を表示できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- plotly, r
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100