Cash flow chart in R?

A cash flow chart is often used to explain derivative financial instruments. It shows winnings at different times. I could not find a great example on the Internet, but it looks something like this:

alt text

I would like to do something roughly equivalent using ggplot2 . My idea was to use a complex graph where the zero axis is somewhere in the middle. Does anyone know how to do this?

Here are some sample 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 is as follows:

alt text

With boxes, it looks like this:

alt text

+4
source share
2 answers

Here is one try.

 ggplot(df, aes(time, xend = time)) + geom_segment(aes(y = 0, yend = positive, colour = "positive"), position = "stack", arrow = arrow()) + geom_segment(aes(y = 0, yend = negative, colour = "negative"), position = "stack", arrow = arrow()) + scale_colour_manual("Direction", values = c("negative" = "red", "positive" = "black")) 

But I think you really need to add the values โ€‹โ€‹yourself, because you are not getting enough control with ggplot2.

+2
source

I suggested this to Khan once for RQuantLib . Now this may be your first patch :)

One problem, I think, is that you may not need a full axis on both sides. Danish zeros will be too small on the x axis, and for standard bonds, different payouts between coupons and the nominal amount will probably also look strange.

Then again this R and fortune("yoda") are still applied.

+1
source

All Articles