现金流图常用于金融工程中解释衍生品。它显示了不同时间的支付。我在网上找不到一个很好的例子,但它看起来像这样:
我想使用
以下是一些示例数据:
![alt text](https://istack.dev59.com/Hq2EW.gif)
ggplot2
制作类似的东西。我的想法是使用堆积条形图,其中零轴位于中间某处。有人知道如何做吗?以下是一些示例数据:
data.frame(time=c(1, 2, 3), positive=c(5, 0, 4), negative=c(-2, 0, 0))
编辑:
感谢 Hadley 的回答;生成的图片如下:
加上方框之后,图片如下:
geom_rect
,它很有效!ggplot(df, aes(time, xend = time)) + geom_rect(aes(xmin=time, xmax=time+1, ymin = 0, ymax = positive, fill = "positive")) + geom_rect(aes(xmin=time, xmax=time+1, ymin = 0, ymax = negative, fill = "negative")) + scale_fill_manual("Direction", values = c("negative" = "red", "positive" = "black"))
- Shane