我正在尝试使用堆叠条形图来显示 2 组值,以使测量 2 组中相同域的值以相反的方向传播,类似于堆叠的负条形图。我通过将一组值设置为负数来“劫持”一个堆积条形图来做到这一点。这给了我想要的图像;但是,我想从底部的堆叠条中删除底片。有没有办法做到这一点?另外,我想知道为什么条形几何中的 width= 选项不调整条形的宽度?例如,当我在 geom_bar 规范中添加 width=0.5 作为选项时,我收到错误:
Warning message:
Stacking not well defined when ymin != 0
无论如何,提前感谢您提供的任何帮助。我的示例代码如下:
test <- structure(list(Mode = structure(c(2L, 1L, 3L, 2L, 1L, 3L), .Label = c("Air","Land", "Sea"), class = "factor"), Side = structure(c(2L, 2L,2L, 1L, 1L, 1L), .Label = c("Allies", "Axis"), class = "factor"),Value = c(72L, 12L, 16L, -84L, -12L, -22L)), .Names = c("Mode", "Side", "Value"), class = "data.frame", row.names = c(NA, -6L))
p <- ggplot(test, aes(x= Mode, y=Value, fill= Mode)) + geom_bar(color = "black", stat="identity", data=subset(test, Side == "Axis")) + geom_bar(color = "black", stat="identity", data=subset(test, Side == "Allies")) + scale_fill_brewer(type = "seq", palette = 1)+ guides(fill=FALSE) + scale_y_continuous(breaks=seq(-100, 100,10))