plot.PrepGR.R 1.42 KB
Newer Older
1
plot.PrepGR <- function(x, type = "l", col.Precip = "royalblue", col.Q = "black", col.na = "grey",
2
                       xlab = NULL, ylab =  NULL, main = NULL, plot.na = TRUE, ...) {
unknown's avatar
unknown committed
3
  
4
5
  if (! any(class(x) %in% "PrepGR")) {
    stop("Non convenient data for x argument. Must be of class \"PrepGR\"")
unknown's avatar
unknown committed
6
7
  }
  
8
9
10
11
12
13
14
15
16
17
18
19
  if (is.null(xlab)) {
    xlab <- "Time"
  }
  if (is.null(ylab)) {
    yunit <- .TypeModelGR(x)$TimeUnit
    ylab  <- paste0(c("precip. [mm/", "flow [mm/"), yunit, "]")
  } else {
    if (length(ylab) < 2) {
      ylab <- c(ylab, "")
    }
  } 
  
unknown's avatar
unknown committed
20
21
22
23
  data <- data.frame(DatesR = x$InputsModel$DatesR,
                     Precip = x$InputsModel$Precip,
                     Qobs   = x$Qobs)
  
24
25
26
  opar <- par(no.readonly = TRUE)
  on.exit(par(opar))
  
unknown's avatar
unknown committed
27
28
29
30
  layout(mat = matrix(1:2), widths = c(1, 2), heights = c(1, 2))
  
  par(mar = c(0.1, 4, 4, 2), xaxt = "n")
  plot(Precip ~ DatesR, data = data, type = "h", col = col.Precip,
31
       xlab = "", ylab = ylab[1L], main = main, ylim = rev(range(data$Precip)))
unknown's avatar
unknown committed
32
33
34
  
  par(mar = c(5, 4, 0.1, 2), xaxt = "s")
  plot(Qobs ~ DatesR, data = data, type = type, col = col.Q,
35
       xlab = xlab, ylab = ylab[2L], main = "")
unknown's avatar
unknown committed
36
37
38
39
40
41
42
43
  
  if (plot.na) {
    axis(side = 1, at = as.POSIXct(data$DatesR[is.na(data$Qobs)]),
         labels = FALSE, lwd.ticks = 3, col.ticks = col.na, tck = 0.025, lend = "butt")	
  
    legend("topright", legend = "NA", pch = 15, col = col.na, bty = "n", cex = 0.8)
  }
  
44
45
  box()
  
unknown's avatar
unknown committed
46
}