我在 Hadoop 集群上运行了一个 Pig 作业,该作业将一堆数据压缩成 R 可以处理的东西来进行群组分析。我有以下脚本,从倒数第二行开始,我的数据格式为:
> names(data)
[1] "VisitWeek" "ThingAge" "MyMetric"
VisitWeek 是一个日期。ThingAge 和 MyMetric 是整数。
数据如下:
2010-02-07 49 12345
我到目前为止的脚本是:
# Load ggplot2 for charting
library(ggplot2);
# Our file has headers - column names
data = read.table('weekly_cohorts.tsv',header=TRUE,sep="\t");
# Print the names
names(data)
# Convert to dates
data$VisitWeek = as.Date(data$VisitWeek)
data$ThingCreation = as.Date(data$ThingCreation)
# Fill in the age column
data$ThingAge = as.integer(data$VisitWeek - data$ThingCreation)
# Filter data to thing ages lt 10 weeks (70 days) + a sanity check for gt 0, and drop the creation week column
data = subset(data, data$ThingAge <= 70, c("VisitWeek","ThingAge","MyMetric"))
data = subset(data, data$ThingAge >= 0)
print(ggplot(data, aes(x=VisitWeek, y=MyMetric, fill=ThingAge)) + geom_area())
最后一行不起作用。我尝试了很多变化、条形图、直方图,但像往常一样,R 文档打败了我。
我希望它显示一个标准的 Excel 样式堆叠面积图 - 每个 ThingAge 的一个时间序列在 x 轴上堆叠在几周内,日期在 y 轴上。这种图表的一个例子在这里:http: //upload.wikimedia.org/wikipedia/commons/a/a1/Mk_Zuwanderer.png
我在这里阅读了文档:http ://had.co.nz/ggplot2/geom_area.html和http://had.co.nz/ggplot2/geom_histogram.html以及这个博客http://chartsgraphs.wordpress。 com/2008/10/05/r-lattice-plot-beats-excel-stacked-area-trend-chart/但我不能让它完全适合我。
我怎样才能做到这一点?