您可以通过自定义来做到这一点x
并使用bargap = 0
在布局中
library(plotly)
#> Loading required package: ggplot2
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
test1 <- data.frame(
city.state = "Newark",
sch.type = c("Charter", "Charter", "District", "District"),
bto.stat = c(0,1,0,1),
y = c(.7, .3, .1, .9),
width = c(.3, .3, .7, .7),
x = c(.15, .15, .65, .65),
annotation.y = c(.3, .8, .05, .55),
all.count = c(46000, 46000, 99000, 99000),
all.y = c(1,1,1,1)
)
bar.test <- plot_ly(type = "bar") %>%
add_trace(x = test1$x,
y = test1$y,
width = test1$width,
marker = list(
color = c("blue", "red", "blue", "red") ,
line = list(color = 'rgba(0,0,0,1)' , width = 2)
)
) %>%
layout(bargap = 0)
bar.test
Created on 2019-11-19 by the reprex package https://reprex.tidyverse.org (v0.3.0)