new version, persistence -7 days
[talweg.git] / R / plot.R
index f551ef4..9a0dbcd 100644 (file)
--- a/R/plot.R
+++ b/R/plot.R
@@ -1,3 +1,29 @@
+#' @title plot curves
+#'
+#' @description Plot a range of curves in data
+#'
+#' @param data Object of class Data
+#' @param indices Range of indices (integers or dates)
+#'
+#' @export
+plotCurves <- function(data, indices)
+{
+       yrange = range( sapply( indices, function(i) {
+               serie = c(data$getCenteredSerie(i))
+               if (!all(is.na(serie)))
+                       range(serie, na.rm=TRUE)
+               c()
+       }) )
+       par(mar=c(4.7,5,1,1), cex.axis=1.5, cex.lab=1.5)
+       for (i in seq_along(indices))
+       {
+               plot(data$getSerie(indices[i]), type="l", ylim=yrange,
+                       xlab=ifelse(i==1,"Temps (en heures)",""), ylab=ifelse(i==1,"PM10",""))
+               if (ii < length(indices))
+                       par(new=TRUE)
+       }
+}
+
 #' @title plot measured / predicted
 #'
 #' @description Plot measured curve (in black) and predicted curve (in red)
@@ -45,8 +71,8 @@ plotFilaments <- function(data, index, limit=60)
                index = i - first_day + 1
                serie = c(data$getCenteredSerie(index), data$getCenteredSerie(index+1))
                if (!all(is.na(serie)))
-                       return ( range(serie, na.rm=TRUE) )
-               return (0)
+                       range(serie, na.rm=TRUE)
+               c()
        }) )
        grays = gray.colors(20, 0.1, 0.9) #TODO: 20 == magic number
        colors = c(