R 中的现金流量图?
在解释金融工程中的衍生品时经常使用现金流量图。它显示了不同时间的回报。我在网上找不到一个很好的例子,但它看起来像这样:
我想做一些粗略的东西等价于使用ggplot2
。我的想法是使用堆叠的 条形图,其中零轴位于中间。有谁知道该怎么做?
以下是一些示例数据:
data.frame(time=c(1, 2, 3), positive=c(5, 0, 4), negative=c(-2, 0, 0))
编辑:
感谢哈德利的回答;生成的图像如下所示:
带框的图像如下所示:
A cashflow diagram is often used when explaining derivatives in financial engineering. It shows the payoffs at different times. I couldn't find a great example online, but it looks something like this:
I would like to make something roughly equivalent using ggplot2
. My thought was to use a stacked bar plot, where the zero axis is somewhere in the middle. Does anyone know how to do this?
Here's some example data:
data.frame(time=c(1, 2, 3), positive=c(5, 0, 4), negative=c(-2, 0, 0))
Edit:
Thanks to Hadley's answer; the resulting image looks like:
With boxes it looks like:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一次尝试。
但我认为你确实需要自己堆叠这些值,因为你无法使用 ggplot2 获得足够的控制。
Here's one attempt.
But I think you really need to stack the values yourself, because you don't get quite enough control with ggplot2.
我曾经向 Khanh 推荐过这个 RQuantLib。现在这可能是你的第一个补丁:)
我认为,有一个问题是你可能不希望任一侧都有完整的轴——长期的零在x轴上会太少,并且对于标准债券,息票和票面金额之间的不同支付也可能看起来很奇怪。
话又说回来,这是 R,并且
fortune("yoda")
仍然适用。I suggested this to Khanh once for RQuantLib. This could now be your first patch :)
One issue, I think, is that you may not want full axis on either side -- long-dated zeros would have too little on the x-axis, and for standard bonds the different payout between coupons and par amount would likely look odd too.
Then again, this is R and
fortune("yoda")
still applies.