You are stacking your data but not your errorbars. To calculate the stacked version of the ymin
and ymax
of the errorbars you can use the ddply
function of the plyr
package.
library(plyr)
mydata2 <- ddply(mydata,.(Day),transform,ybegin = cumsum(Val) - Error,yend = cumsum(Val) + Error)
ggplot(data=mydata2, aes(x=Day,y=Val, fill=Cat)) +
geom_area() +
geom_errorbar(aes(ymax=ybegin , ymin= yend ),width=.5, color="black")
Output: