[R] Plot_ly bar plots - bars span sevral x values when there are missing values.
nevil amos
nev||@@mo@ @end|ng |rom gm@||@com
Thu Mar 18 23:35:54 CET 2021
Hi Rasmus,
thanks for that suggestion. It does indeed fix the column widths in this
example. the reason it does this is becuase it means that the additonal 0
values added result in values for two adjacent columns.
so if adjacent columns are present the "correct" column width is maintained
df[c(3,4),]%>%plot_ly(
x = ~ x,
y = ~ y,
type = "bar")%>%
layout(xaxis = list(range = c(0,20)),
title = "adjcant x values get correct column width")
however if there are not tow adjacent columns then the width increases
df[c(3,5),]%>%plot_ly(
x = ~ x,
y = ~ y,
type = "bar")%>%
layout(xaxis = list(range = c(0,20)),
title = "gap between x values column width changes")
given this I'm still not sure why the single value example produces a
correct column width.
for now the generic work around is to pad with y=0 as you suggested.
On Wed, 10 Mar 2021 at 05:58, Rasmus Liland <jral using posteo.no> wrote:
> Dear Nevil,
>
> Although I am a bit unfamiliar with
> plotly, it seems it is possible to plot
> two bars side by side at least:
>
> h <- df[3:4,]
> p <- plotly::plot_ly(
> data = h,
> x = ~ x,
> y = ~ y,
> type = "bar")
> p <- plotly::layout(p=p,
> xaxis = list(range = c(0,20)),
> title = "example 4 two bars side by side")
> plotly::orca(p=p, file="amos4.png")
>
> Thus, if you want to only plot x=3 and
> x=11 you need to set y=0 when x=4:10:
>
> h <- df[c(3, 11),]
> h <- rbind(h, cbind(x=4:10, y=0))
> p <- plotly::plot_ly(
> data = h,
> x = ~ x,
> y = ~ y,
> type = "bar")
> p <- plotly::layout(p=p,
> xaxis = list(range = c(0,20)),
> title = "example 2 corrected")
> plotly::orca(p=p, file="amos2.png")
>
> I think this has to do with the xaxis
> option in plotly::layout there, and not
> with the bar width.
>
> Best,
> Rasmus
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list