various fixes (especially in plotFbox and Neighbors shape predict
[talweg.git] / pkg / R / plot.R
index 7b5f2b5..5cb55b0 100644 (file)
@@ -29,7 +29,7 @@ plotCurves <- function(data, indices=seq_len(data$getSize()))
 #' @description Plot measured curve (in black) and predicted curve (in red)
 #'
 #' @param data Object return by \code{getData}
-#' @param pred Object as returned by \code{getForecast}
+#' @param pred Object as returned by \code{computeForecast}
 #' @param index Index in forecasts
 #'
 #' @export
@@ -109,7 +109,7 @@ computeFilaments <- function(data, index, limit=60, plot=TRUE)
 #'
 #' @description Plot histogram of similarities (weights)
 #'
-#' @param pred Object as returned by \code{getForecast}
+#' @param pred Object as returned by \code{computeForecast}
 #' @param index Index in forecasts (not in data)
 #'
 #' @export
@@ -124,9 +124,9 @@ plotSimils <- function(pred, index)
 
 #' @title Plot error
 #'
-#' @description Draw error graphs, potentially from several runs of \code{getForecast}
+#' @description Draw error graphs, potentially from several runs of \code{computeForecast}
 #'
-#' @param err Error as returned by \code{getError}
+#' @param err Error as returned by \code{computeError}
 #' @param cols Colors for each error (default: 1,2,3,...)
 #'
 #' @seealso \code{\link{plotPredReal}}, \code{\link{plotFilaments}}, \code{\link{plotSimils}}
@@ -196,13 +196,16 @@ plotFbox <- function(data, filter=function(index) TRUE, plot_bivariate=TRUE)
                end_index = data$getSize() - 1
        }
 
+       L = length(data$getCenteredSerie(2))
        series_matrix = sapply(start_index:end_index, function(index) {
-               as.matrix(data$getSerie(index))
+               if (filter(index))
+                       as.matrix(data$getSerie(index))
+               else
+                       rep(NA,L)
        })
-       # Remove NAs. + filter TODO: merge with previous step: only one pass required...
-       nas_indices = seq_len(ncol(series_matrix))[ sapply( 1:ncol(series_matrix),
-               function(index) ( !filter(index) || any(is.na(series_matrix[,index])) ) ) ]
-       series_matrix = series_matrix[,-nas_indices]
+       # TODO: merge with previous step: only one pass should be required
+       no_NAs_indices = sapply( 1:ncol(series_matrix), function(i) all(!is.na(series_matrix[,i])) )
+       series_matrix = series_matrix[,no_NAs_indices]
 
        series_fds = rainbow::fds(seq_len(nrow(series_matrix)), series_matrix)
        if (plot_bivariate)