diff options
author | Suraj Yerramilli | 2016-02-24 15:05:10 +0530 |
---|---|---|
committer | Suraj Yerramilli | 2016-02-24 15:05:10 +0530 |
commit | 6737b33bb58a7b864326d0597aa683e8b1eb70a8 (patch) | |
tree | c49f85b81864840e4b0a0d3361814e0db91ad519 /R/nonparam.R | |
parent | 55b5704c4042761d1efc6f129b3068176fd50b04 (diff) | |
download | SysID-R-code-6737b33bb58a7b864326d0597aa683e8b1eb70a8.tar.gz SysID-R-code-6737b33bb58a7b864326d0597aa683e8b1eb70a8.tar.bz2 SysID-R-code-6737b33bb58a7b864326d0597aa683e8b1eb70a8.zip |
changed impulseplot engine to ggplot2
Diffstat (limited to 'R/nonparam.R')
-rw-r--r-- | R/nonparam.R | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/R/nonparam.R b/R/nonparam.R index 487dbcd..99907e1 100644 --- a/R/nonparam.R +++ b/R/nonparam.R @@ -87,25 +87,29 @@ impulsechannel <- function(y,u,N,M,K=0,regul=F,lambda=1){ #' @param sig Significance Limits (Default: \code{0.975}) #' #' @seealso \code{\link{impulseest}},\code{\link{step}} +#' @import ggplot2 +#' #' @export plot.impulseest <- function(model,sig=0.975){ - par(mfrow=c(model$noutputs,model$ninputs)) + plotseq <- seq(model$noutputs*model$ninputs) + g <- vector("list",model$nin*model$nout) - impulseplot <- function(model,sig){ - lim <- model$se*qnorm(sig) - - max <- max(abs(coef(model))) - ylim <- c(-max,max) - - title <- paste("Impulse Response \n From",model$x,"to",model$y) - plot(model$lags,coef(model),type="h",xlab="Lag",ylab= "IR Coefficient", - main = title) - abline(h=0);points(x=model$lags,y=lim,col="blue",lty=2,type="l") - points(x=model$lags,y=-lim,col="blue",lty=2,type="l") + for(i in plotseq){ + z <- model[[i]] + lim <- z$se*qnorm(sig) + yindex <- (i-1)%/%model$nin + 1;uindex <- i-model$nin*(yindex-1) + df <- data.frame(x=z$lags,y=coef(z),lim=lim) + g[[i]] <- ggplot(df,aes(x,y))+ + geom_segment(aes(xend=x,yend=0))+geom_hline(yintercept = 0) + + geom_point(size=2) + ggtitle(paste("From",z$x,"to",z$y))+ + geom_line(aes(y=lim),linetype="dashed",colour="steelblue") + + geom_line(aes(y=-lim),linetype="dashed",colour="steelblue") + + theme_bw(14) + ylab(ifelse(uindex==1,"IR Coefficients","")) + + xlab(ifelse(yindex==model$nout,"Lags","")) + + theme(axis.title=element_text(color = "black",face = "plain"), + title=element_text(size=10,color = "gray",face="bold")) } - - l <- model[seq(model$noutputs*model$ninputs)] - p <- lapply(l,impulseplot,sig=sig) + multiplot(plotlist=g,layout=plotseq) } |