R 创建堆积面积图

R create a stacked area plot

我知道有几个关于堆积面积图的问题,但我相信我的情况不同。 我有来自 income/expense 民意调查的数据,我想显示按人口百分位划分的平均支出构成的堆积面积图。

因此,按百分位数汇总后,我的数据如下所示:

Perce    Food    Wear    Car
1        23      15      0
2        25      18      0
..       ..      ..      ..
..       ..      ..      ..
..       ..      ..      ..
99       745     533     300
100      900     800     673

这很难,因为我要堆叠的值在不同的变量上。

感谢任何帮助!

您正在寻找这样的东西吗?如果你做了一个最小的可重现的例子来配合你的问题,它会更容易帮助你,因为我不知道你的实际数据是什么样的。

# install.packages("ggplot2", dependencies = TRUE)
library(ggplot2)

data.set <- data.frame(
  Time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)),
  Type = rep(c('Wear', 'Food ', 'Car', 'Pedestrian'), 4),
  Perce = rpois(16, 10)
)

p <- qplot(Time, Perce, data = data.set, fill = Type, geom = "area")
p + scale_fill_brewer(palette="Spectral")