Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(ggplot2)
- N <- 30
- Date <- economics$date[1:N]
- Pop <- economics$pop[1:N]
- DateCount<-c(1:N)
- df <- data.frame(DateCount,Date,Pop)
- trendCoef <- lm(Pop ~ DateCount)
- k<-trendCoef$coefficients[[2]]
- b<-trendCoef$coefficients[[1]]
- x <- c(1:N)
- y <- c()
- for(i in x){
- y <- append(y, k*i+b)
- }
- trend <- data.frame(x,y)
- 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