
Untitled
By: a guest on
Jul 29th, 2012 | syntax:
None | size: 1.34 KB | hits: 10 | expires: Never
Combined positive and negative stacked line plots
p <- ggplot(dataForm, aes(x=Time,y=Value,group=Type),colour=factor(Type))
p + geom_line(aes(fill = Type),position = "stack")
p <- ggplot(dataForm, aes(x=Time,y=Value,group=Type),colour=factor(Type))
p + geom_line(data = data1,aes(fill = Type),position = "stack")
p + geom_line(data = data1,aes(fill = Type),position = "stack")
library(ggplot2)
library(plyr)
data = read.table(text="Time Type Value
1 a 8
2 a 10
3 a 10
4 a 5
5 a 3
1 b 9
2 b 5
3 b 7
4 b 8
5 b 3
1 c -3
2 c -1
3 c -5
4 c -4
5 c -7
1 d -11
2 d -3
3 d -9
4 d -6
5 d -6", header=TRUE)
p <- ggplot(data, aes(x=Time))
p <- p + geom_line(subset = .(Type %in% c('a', 'b')),
aes(y=Value, colour = Type),
position = 'stack')
p <- p + geom_line(subset = .(Type %in% c('c', 'd')),
aes(y=Value, colour = Type),
position = 'stack')
p
p <- ggplot(data, aes(x=Time))
p <- p + geom_area(subset = .(Type %in% c('a', 'b')),
aes(y=Value, fill=Type),
position = 'stack')
p <- p + geom_area(subset = .(Type %in% c('c', 'd')),
aes(y=Value, fill = Type),
position = 'stack')
p <- p + geom_hline(yintercept=0)
p