R/plot.SPTMseason.R

Defines functions plot.SPTMseason

Documented in plot.SPTMseason

#' Update the seasons for LU
#'
#' Update the seasons for LU
#' @param season.sites the season calculated for each site.
#' @param p.sites the composition of each site.
#' @keywords updating season
#' @export
#' @examples
#' data("wq_analysis_week2")
#' SPTMData(wq.raw.obs, frequency = "quarter")
plot.SPTMseason = function(SPTMobj,xlab="Date", ylab="", select = NULL, cex.axis=NULL, n_x_lab = 7){

  dim.s = attr(SPTMobj,"dimSeason")

  n.comp = ncol(SPTMobj) / dim.s

  if(is.null(select)){select = 1:n.comp}

  n.disp  = length(select)

  color = c("darkgreen","orange")
  if(dim.s > 2){color = brewer.pal(dim.s, "Set2")}

if(floor(sqrt(n.disp)) == sqrt(n.disp)){
  dim.plot = c(sqrt(n.disp), sqrt(n.disp))
}else{
  dim.plot = c(floor(sqrt(n.disp)+1), floor(sqrt(n.disp)+1))
  reduction = floor((prod(dim.plot) - n.disp) / dim.plot[1])
  dim.plot = dim.plot - c(reduction, 0)
}

par(mfrow = dim.plot)


if(is.null(cex.axis)){cex.axis = 0.7}

for(i in select){
  idx = i + n.comp*(0:(dim.s-1))
  plot(1, type="n", xlab = xlab, ylab = ylab, xlim = c(0,nrow(SPTMobj)+1), ylim = 1.2*range(SPTMobj, na.rm=T),
       main = attr(SPTMobj, "nameComp")[i], axes = F,cex.main = 1)
  axis(2)
  axis(1, at = seq.int(1,nrow(SPTMobj), length.out = n_x_lab), cex.axis = cex.axis,
       labels = as.yearmon(rownames(SPTMobj))[seq.int(1,nrow(SPTMobj), length.out = n_x_lab)], las = 2)
  abline(h  =0, col = "lightgrey")
  for(j in 1:dim.s){
    idx.j = idx[j]
    points(SPTMobj[,idx.j],type = "l", col = color[j])
  }
  legend("bottomleft", legend = attr(SPTMobj, "nameBasis"), bty = 'n',
         lty = rep(1,length(attr(SPTMobj, "nameBasis"))), lwd = rep(2,length(attr(SPTMobj, "nameBasis"))), col = color, cex = 0.8)
}
}
ick003/SpTMixture documentation built on May 18, 2019, 2:32 a.m.