I'm plotting a series of financial projections with ggplot's geom_path().
ggplot(df,aes(year,pot,color=iRate)) + geom_path() + theme(legend.position="none") + ylim(0,300000)
This is what I have..[sorry it's a link]
..two of the paths hit the right hand edge, year 40, but then nip back to their beginning. One line doesn't. This isn't a problem of axis-display limits, nor of a rogue line in the data frame - if I remove all years < 5 the same thing happens. It may be a just problem of overburdening the plotting device, but it is repeatable..
There are questions asking how to 'close' a geom_path which don't answer this. How do I ensure the path stays 'open'?
inflation <- seq(1, 1.1, 0.02)
potGrowth <- seq(1.02, 1.1, 0.02)
div <- 10000
initcapital <- 100000
output <- numeric()
lifespan <- 40
delay <- 10
for(j in 1:length(inflation)){
str <- rep(0,lifespan)
for(i in delay:lifespan){ str[i] <- floor((inflation[j]^i)*div) }
for(k in 1:length(potGrowth)){
cap <- initcapital
for(i in 1:lifespan){
cap <- cap-str[i]; cap <- cap*potGrowth[k]
output <- append(output, floor(cap))
}
}
}
iLen <- length(inflation); gLen <- length(potGrowth)
simulations <- iLen*gLen
df <- data.frame(pot=output, projection=rep(1:simulations,each=lifespan), iRate=rep(inflation,each=lifespan*gLen), gRate=rep(rep(potGrowth,each=lifespan),times=iLen), year=rep(1:lifespan,times=simulations))
and here it is solved by inserting group=projection
ggplot(df,aes(year,pot,color=iRate,group=projection)) + geom_path() ...