How can I create a projection graph as appears on this page: http://www.businessinsider.in/Heres-A-Terrifying-Chart-Of-Projected-Ebola-Cases/articleshow/43259377.cms
My data:
> ddf
time value
1 1 10
2 2 18
3 3 30
4 4 38
5 5 45
6 6 61
7 7 78
>
> dput(ddf)
structure(list(time = 1:7, value = c(10L, 18L, 30L, 38L, 45L,
61L, 78L)), .Names = c("time", "value"), class = "data.frame", row.names = c(NA,
-7L))
I want to project it to time 20.
You can use ggplot2's stat_smooth
function with a forecasting method of your choise.
Use fullrange=TRUE
to predict it for the whole range.
require(ggplot2)
ggplot(aes(x=time,y=value), data=ddf) + geom_point() +
stat_smooth(method="lm", fullrange=TRUE, lty="dotdash") + xlim(1,20) +
stat_smooth(method="lm")
If you also want the vertical line: Add + geom_vline(xintercept=7)