Problems with barcharts with barmode='overlay' and Date objects
まだ誰も着手していません。
- 主要言語
- R
- スター
- 2.7k
- フォーク
- 641
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I need to plot several barcharts with Date objects on the x-axis with barmode = 'overlay' for a whole year. When there are enough values to plot, everything works fine, as I would like the bars to have equal widths along all traces.
But when one trace has few elements, the width of those traces are expanded.
And when one trace only has 1 value, it is not shown at all.
I could overcome those problems by creating fictional Dates with 0 y-values for the rest of the year, but I was hoping there is a better way of solving that.
The variable n in the example can be used to determine the amount of bars for the problematic
trace.
library(plotly)
n = 3
## All days of 2019 ###############
Days2019 <- data.frame(
date = seq(as.Date("2019-01-01"), as.Date("2019-12-31"), by = "days")
)
## Sample n Days of 2019 ###############
df <- data.frame(
date = sort(sample(Days2019$date, size = n, replace = F)),
val = sample(1:100, n, replace = T)
)
## Merge fictional 0 y-Values #################
# df = merge(df, Days2019, by="date", all=T)
# df[is.na(df$val),]$val=0
## Sample 30 Days of 2019 ###############
holiday1 <- data.frame(
date = sort(sample(Days2019$date, size = 30, replace = F))
)
## Plot Plotly ###############
maxY = max(df$val)
plot_ly() %>%
add_trace(data = holiday1, x = ~date, y = maxY, marker = list(color = "gray"), type="bar", name="Holidays") %>%
add_trace(data = df, x = ~date, y = ~val, marker = list(color = "red"), type="bar", name="Values") %>%
plotly::layout(autosize = F,
barmode = 'overlay',
bargap = 0.05,
xaxis = list(
type = "date",
range = c(as.Date("2019-01-01")-1,
as.Date("2019-12-31")+1),
autorange = FALSE,
tickmode = "auto",
nticks = 14L,
automargin = F)
)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供されている R の例を n=3 で実行し、次に n を変化させて、2 つの trace 間で overlay モードにおけるバーの幅と可視性を比較します。この例で使用されている plotly.R のバーおよび Date の処理を追跡し、疎な Date trace が適切な幅を維持し、架空のゼロ値の日付を必要とせずに単一の値がレンダリングされれば、issue は完了とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- r
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100