【发布时间】:2020-03-14 09:50:29
【问题描述】:
我正在尝试使用 Plotly 在 R 中创建 Marimekko 图表。本质上,这只是一个堆叠的、可变宽度的条形图,两个条形直接相邻。目前,我的尝试如下所示:
创建它的代码在这里:
bar.test <- plot_ly(type = "bar") %>%
layout(title = paste0("Newark Charter vs District BTO Makeup"),
xaxis = list(title = ""),
yaxis = list(title = "Percent BTO", tickformat = "%")) %>%
add_trace(x = ~test1$sch.type, y = ~test1$y, width = ~test1$width,
marker = list(color = c(blue.dark.opq, red.opq.2, blue.dark.opq, red.opq.2) ,
line = list(color = 'rgba(0,0,0,1)' , width = 2))) %>%
add_annotations(x = ~test1$sch.type, y = ~test1$annotation.y,
text = paste0("<b>", 100*round(test1$y, 3), "%"),
showarrow = F,
font = list(size = 14, color = 'rgba(0,0,0,1)')) %>%
add_annotations(x = ~test1$sch.type, y = ~test1$all.y,
text = paste0(test1$all.count), showarrow = F,
font = list(size = 14, color = 'rgba(0,0,0,1)')) %>%
hide_legend()
数据看起来像这样:
我的目标只是让钢筋之间没有间隙。我曾尝试使用 bargap 参数来做到这一点,但已经读到为条形分配宽度会使 Plotly 忽略 bargap 参数。我还阅读了一个潜在的解决方法是手动更改条形的offset 参数。但是,我有许多具有不同宽度和百分比的数字,因此任何解决方案都不能是手动的。
【问题讨论】:
-
无论如何,当您提供数据的名称时,您不需要使用
~。使用~或test1$