r - plotting; adding own x-axis does not work -


i plot time-series data. illustrate dates on x-asis, first removed values on axis add on axsis correct dates:

set.seed(1) r <- rnorm(20,0,1) z <- c(1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1) data <- as.data.frame(na.omit(cbind(z, r))) series1 <- ts(cumsum(c(1,data[,2]*data[,1]))) series2 <- ts(cumsum(c(1,data[,2]))) d1y <- seq(as.date("1991-01-01"),as.date("2015-01-01"),length.out=24)  plot_strategy <- function(series1, series2, currency)   {x11()  matplot(cbind(series1, series2), xaxt = "n", xlab = "time",           ylab = "value", col = 1:3, ann = true, type = 'l',           lty = 1)  axis(1, at=as.posixct(d1y),labels=format(d1y,"%y"))  title(ylab = "value")  title(xlab = "time")   legend(x = "topleft", legend = c("tr", "ba"),         lty = 1,col = 1:3)  dev.copy2pdf(file= currency, width = 11.69, height = 8.27)}  plot_strategy(series1, series2,               currency= "all.pdf") 

however, new x-axis doesn't show up. suggestions?

set.seed(1) r <- rnorm(20,0,1) z <- c(1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1) data <- as.data.frame(na.omit(cbind(z, r))) series1 <- ts(cumsum(c(1,data[,2]*data[,1]))) series2 <- ts(cumsum(c(1,data[,2]))) d1y <- seq(as.date("1991-01-01"),as.date("2015-01-01"),length.out=24)  matplot(cbind(series1, series2), xaxt = "n", xlab = "time",          ylab = "value", col = 1:3, ann = true, type = 'l',           lty = 1) axis(1, at=seq(2,20,2), labels=format(d1y[seq(2,20,2)],"%y")) 

enter image description here


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -