No way to make legend order exactly match bar order in relative stacked bar plot
オープン
まだ誰も着手していません。
- 主要言語
- R
- スター
- 2.7k
- フォーク
- 641
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Sometimes we want to plot negative values below x axis in a stacked bar plot. This can be done with barmode as "relative".
Further, I want to make the legend order exactly match the bar order in plot. However the positive bars stack from middle to top, negative bars stack from middle to down, thus no matter how I arrange the variable levels, there is no way to make the legend order exactly match bar order.
library(plotly)
library(data.table)
set.seed(42)
dt_test <- data.table(x = rep(1:5, each = 6), variable = rep(letters[1:6], 5), value = sample(10:40, 30))
dt_test[variable %in% letters[3:5], value := -value]
dt_test[, variable := factor(variable, levels = c("c", "d", "e", "a", "b", "f"))]
plot_ly(dt_test) %>%
add_bars(x = ~x, y = ~value, color = ~variable) %>%
layout(barmode = 'relative', legend = list(traceorder = "reversed"))

I'm not sure how this can be done, unless we
- change the stack order in negative part as bottom up
- or can arrange legend order freely without changing bar stack order
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、plot_ly()、add_bars()、barmode = "relative"、および現在の凡例設定を使用して、提供された R の例を再現します。負のスタックと正のスタックで要求された動作をサポートできるか調査します。凡例の順序が表示されるバーの順序と完全に一致するか、または制限事項と選択した順序動作が文書化されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- r
- 領域
- data-visualization
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100