Skip to content

Instantly share code, notes, and snippets.

@JoshAshby
Created April 28, 2011 00:37
Show Gist options
  • Save JoshAshby/945563 to your computer and use it in GitHub Desktop.
Save JoshAshby/945563 to your computer and use it in GitHub Desktop.
Displays only the last period of a dataset with design \|\|\|\ (\ = descending slope. | = restock)
library(ggplot2)
mydata = read.csv("/home/joshua/Downloads/test_data.csv", header = TRUE)
m = length(mydata$x)
theta = matrix(c(0,0), nrow=1)
ux = matrix(c(rep(1,m), mydata$x), ncol=2)
uy= matrix(mydata$y, ncol=1)
for (i in 0:m) {
j = (m - i)
if (uy[(j)] > uy[(j-1)]) {
oy=matrix(uy[j:m], ncol=1)
ox=matrix(c(rep(1,(i+1)), ux[j:m,2]), ncol=2)
break
}
}
oy
ox
plot = ggplot(mydata, aes(x[j:m], y[j:m])) + geom_point() + ylab('Quantity') + xlab('Days')
plot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment