plot.ObsGR.R 1.14 KB
Newer Older
unknown's avatar
unknown committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
plot.ObsGR <- function(x, type = "l", col.Precip = "royalblue", col.Q = "black", col.na = "grey",
                       xlab = "Time", ylab = c("Precipitation [mm]", "Flow [mm]"), main = "", plot.na = TRUE, ...) {
  
  if (! any(class(x) %in% "ObsGR")) {
    stop("Non convenient data for x argument. Must be of class \"ObsGR\"")
  }
  
  data <- data.frame(DatesR = x$InputsModel$DatesR,
                     Precip = x$InputsModel$Precip,
                     Qobs   = x$Qobs)
  
  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,
       xlab = "", ylab = ylab[1L], main = "", ylim = rev(range(data$Precip)))
  
  par(mar = c(5, 4, 0.1, 2), xaxt = "s")
  plot(Qobs ~ DatesR, data = data, type = type, col = col.Q,
       xlab = xlab, ylab = ylab[2L], main = main)
  
  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)
  }
  
}