我想制作一个反向金字塔图,其中酒吧堆叠在一起,宽度不同。ggplot2 - 不同宽度的堆叠酒吧
第一,我有堆积条形图如下代码示例
library(dplyr)
library(ggplot2)
sample <- data_frame(x=c(1, 1, 1, 1, 2, 2, 2, 2),
y=c(5,10,15, 20, 10, 5, 20, 10),
w=c(1, 2, 3, 4, 1, 2, 3, 4),
group=c("a", "b", "c", "d", "a", "b", "c", "d"))
ggplot() +
geom_bar(data=sample,
aes(x=x,y=y,group=group, fill=group),
stat="identity", position=position_stack())
然后,我添加宽度aes
所以具有较低w
值将变小,同时他们仍然堆叠在彼此。但是,酒吧没有堆叠警告。
ggplot() +
geom_bar(data=sample,
aes(x=x,y=y,group=group, fill=group, width=w/5),
stat="identity", position=position_stack())
Warning: Ignoring unknown aesthetics: width
Warning message:
position_stack requires non-overlapping x intervals
任何有助于对堆叠化妆柱状图中或在不同的图表类型,可以覆盖类似的概念想法,将不胜感激。谢谢!