Guest User

Untitled

a guest
May 20th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. library(ggplot2)
  2.  
  3. N <- 30
  4.  
  5. Date <- economics$date[1:N]
  6. Pop <- economics$pop[1:N]
  7.  
  8. DateCount<-c(1:N)
  9.  
  10. df <- data.frame(DateCount,Date,Pop)
  11.  
  12. trendCoef <- lm(Pop ~ DateCount)
  13. k<-trendCoef$coefficients[[2]]
  14. b<-trendCoef$coefficients[[1]]
  15. x <- c(1:N)
  16. y <- c()
  17. for(i in x){
  18. y <- append(y, k*i+b)
  19. }
  20. trend <- data.frame(x,y)
  21.  
  22. ggplot()+geom_line(data=trend, aes(x, y), color="red")+geom_line(data=df, aes(DateCount, Pop))
Add Comment
Please, Sign In to add comment