如何调整R中条形图的宽度

How to resize the width of the bar graph in R plotly

如何确保 1 月 1 日到 3 日之间的 'gap' 等于 1 月 1 日的柱形大小?

目前的情节误导了读者,因为 1 月 2 日的差距应该与 1 月 1 日的差距一样大。

library(plotly)
library(lubridate)

dat  = data.frame(a =c( dmy("1/1/22") , dmy("3/1/22"),dmy("6/1/22")) , b = c(1,1,4))

> dat
           a b
1 2022-01-01 1
2 2022-01-03 1
3 2022-01-06 4

plot_ly(dat , x = ~a, y = ~b , type = "bar")

 

您可以在layout()中设置bargap(介于或等于0和1之间)来调整柱之间的间距。

dat %>%
  plot_ly(x = ~a, y = ~b, type = "bar") %>%
  layout(bargap = 0.5)