Tuesday, March 13, 2018

Plotting into the Future

Here's an obvious but useful idea for plotting the anticipated trend over time for a simple linear relationship.

Imagine that you are tracking the size of something each day for 10 days (e.g., growth in log file size) and you want a graph of expected growth through the end of the month (30 days) based on the data collected so far. In this example, growth was checked and noted everyday, with a break on the weekend (day 6 and 7), so the ten days of data collection span 12 calendar days. When plotting the series, simply set xlim to (1,30) and fullrange = TRUE to see the anticipated growth for entire month.
library(ggplot2)
mydf
   day growth
1    1   79.7
2    2   80.0
3    3   80.4
4    4   81.2
5    5   82.0
6    8   83.6
7    9   84.0
8   10   84.5
9   11   85.3
10  12   85.9

ggplot(mydf, aes(x=day, y=growth)) + 
  geom_point() + 
  xlim(1,30) + 
  stat_smooth(method="lm", fullrange = TRUE) +
  ggtitle("Anticipated growth over 30 days") +
  labs(y = "Size")



No comments: