R创建堆积区域图

时间:2015-08-10 16:10:05

标签: r plot ggplot2 data-analysis

我知道堆积区域有几个问题,但我相信我的情况不同。 我有来自收入/支出调查的数据,我想显示按人口百分比计算的费用平均构成的堆积区域图。

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

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

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

任何帮助表示赞赏! enter image description here

1 个答案:

答案 0 :(得分:1)

这样的事情会是你想要的吗?如果您制作一个可重复性最小的示例来回答您的问题,那么您可以更轻松地帮助您,因为我不知道您的实际数据是什么样的。

scale_fill_brewer

# 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")