小编an_*_*_ja的帖子

在ggplot中具有不同宽度的堆积条形图

我尝试构建一个具有不同宽度的堆积条形图,以便宽度表示分配的平均数量,而高度表示分配的数量。

接下来,您会发现我的可重复数据:

procedure = c("method1","method2", "method3", "method4","method1","method2", "method3", "method4","method1","method2", "method3","method4")
sector =c("construction","construction","construction","construction","delivery","delivery","delivery","delivery","service","service","service","service") 
number = c(100,20,10,80,75,80,50,20,20,25,10,4)
amount_mean = c(1,1.2,0.2,0.5,1.3,0.8,1.5,1,0.8,0.6,0.2,0.9) 

data0 = data.frame(procedure, sector, number, amount_mean)
Run Code Online (Sandbox Code Playgroud)

使用 geom_bar 并在 aes 中包含宽度时,我收到以下错误消息:

position_stack requires non-overlapping x intervals. Furthermore, the bars are no longer stacked. 
Run Code Online (Sandbox Code Playgroud)
bar<-ggplot(data=data0,aes(x=sector,y=number,fill=procedure, width = amount_mean)) + 
geom_bar(stat="identity") 
Run Code Online (Sandbox Code Playgroud)

我还查看了 mekko-package,但似乎这仅适用于条形图。

这是我最终想要的(不是基于上述数据):

期望的结果(不基于上述数据)

知道如何解决我的问题吗?

r ggplot2

7
推荐指数
1
解决办法
608
查看次数

标签 统计

ggplot2 ×1

r ×1