0

I have a CSV file which looks like this:

Time ColA ColB ColC
0    1    10   5
1    3    7    15
2    0    8    9
3    3    4    5
4    4    5    6
5    10   23   4

I'd like to plot this as a stacked area chart, as follows (ignoring the X-axis labels):

Stacked area chart

But most packages seem to require several transformations of the data. Is there a way to simply specify an X column and the various Y columns to be stacked?

Richard
  • 56,349
  • 34
  • 180
  • 251
  • You should really share what you've attempted so far. (Doing this in ggplot2 will definitely involve reshaping the data.) – joran Aug 22 '13 at 15:57
  • 3
    dup -> http://stackoverflow.com/questions/5030389/getting-a-stacked-area-plot-in-r ?? – statquant Aug 22 '13 at 16:01

1 Answers1

0

The following ended up working well enough.

The reshape library pulls in the melt command which recognises the data into a format usable by ggplot.

library(ggplot2)
library(reshape)
data=read.csv("out20",comment.char = "#",sep = "")
mdata=melt(data,id=c("Time"))
ggplot(mdata, aes(x=Time,y=value,group=variable,fill=variable)) + geom_area(position="fill")
Richard
  • 56,349
  • 34
  • 180
  • 251