plot.PrepGR.R 1.4 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, ...) {
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
  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, "")
    }
18
19
  }

unknown's avatar
unknown committed
20
21
22
  data <- data.frame(DatesR = x$InputsModel$DatesR,
                     Precip = x$InputsModel$Precip,
                     Qobs   = x$Qobs)
23

24
25
  opar <- par(no.readonly = TRUE)
  on.exit(par(opar))
26

unknown's avatar
unknown committed
27
  layout(mat = matrix(1:2), widths = c(1, 2), heights = c(1, 2))
28

unknown's avatar
unknown committed
29
30
  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)))
32

unknown's avatar
unknown committed
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 = "")
36

unknown's avatar
unknown committed
37
38
  if (plot.na) {
    axis(side = 1, at = as.POSIXct(data$DatesR[is.na(data$Qobs)]),
39
40
         labels = FALSE, lwd.ticks = 3, col.ticks = col.na, tck = 0.025, lend = "butt")

unknown's avatar
unknown committed
41
42
    legend("topright", legend = "NA", pch = 15, col = col.na, bty = "n", cex = 0.8)
  }
43

44
  box()
45
46

}