RegPatterns <- function(ano, lon, lat, PCs, nPCs = 4, 
                        nrow = NULL, ncol = NULL, show = FALSE, var = NULL) {
  nlat <- length(lat)
  nlon <- length(lon)

  proj.regr <- array(NA, c(nPCs, nlat, nlon))

  ## Regress the PC:
  for (t in 1:nPCs) {
    ## Standardize the PC before proyecting it:
    PCs.stand <- (PCs[,t] - mean(PCs[,t])) / sd(PCs[,t])
    pos.time <- which(dim(ano) == length(PCs.stand))
    lm_fun <- function(x,y) lm(y~x)$coefficients[[2]]
    proj.regr[t,,] <- apply(ano, (1:length(dim(ano)))[-pos.time], lm_fun, x=PCs.stand)
  }

  if (show) {
  
  
    ## plot title:
    if(is.null(var)) plot.titles <- paste0("pattern #", 1:nPCs) else plot.titles <- paste0("pattern #", 1:nPCs, "  (", round(var[1:nPCs],1), "% tot.var)")
    
    PlotLayout(PlotEquiMap, c(2,3), var=proj.regr, lat=lat, lon=lon, 
               filled.continents=FALSE, bar_scale=.5, 
               nrow=nrow, ncol=ncol, titles=plot.titles)
    invisible(proj.regr)
  } else {
    proj.regr
  }
}


