summaryrefslogtreecommitdiff
path: root/R/twa.R
diff options
context:
space:
mode:
authorRanke Johannes <johannes.ranke@agroscope.admin.ch>2025-01-29 15:44:35 +0100
committerRanke Johannes <johannes.ranke@agroscope.admin.ch>2025-01-29 15:44:35 +0100
commit2bf16e09ca3c451cb26eee108dc95764576d084d (patch)
tree8663f6c07533c724ba1a391865c72652654f43d1 /R/twa.R
parente6dfdecf78c448f3a0947c3e70806697c7586bc3 (diff)
Fix plot.one_box() for the case that a twa is shown
Diffstat (limited to 'R/twa.R')
-rw-r--r--R/twa.R7
1 files changed, 5 insertions, 2 deletions
diff --git a/R/twa.R b/R/twa.R
index 886351d..2018dfa 100644
--- a/R/twa.R
+++ b/R/twa.R
@@ -131,6 +131,7 @@ one_box.mkinfit <- function(x, ini = "model", ..., t_end = 100, res = 0.01) {
#' fit_2 <- mkinfit(m_2, FOCUS_2006_D, quiet = TRUE)
#' pred_2 <- one_box(fit_2, ini = 1)
#' pred_2_saw <- sawtooth(pred_2, 2, 7)
+#' plot(pred_2_saw)
#' plot(pred_2_saw, max_twa = 21, max_twa_var = "m1")
plot.one_box <- function(x,
xlim = range(time(x)), ylim = c(0, max(x)),
@@ -148,7 +149,9 @@ plot.one_box <- function(x,
x_twa$window_end[max_twa_var], value, col = "grey")
text(x_twa$window_end[max_twa_var], value, paste("Maximum:", signif(value, 3)), pos = 4)
# Plot a second time to cover the grey rectangle
- matlines(time(x), as.matrix(x), lty = 1:length(obs_vars), col = 1:length(obs_vars))
+ plot.ts(x, plot.type = "single", xlab = xlab, ylab = ylab,
+ lty = 1:length(obs_vars), col = 1:length(obs_vars),
+ las = 1, xlim = xlim, ylim = ylim)
}
}
@@ -229,7 +232,7 @@ twa.one_box <- function(x, window = 21)
resolution = 1/frequency(x)
n_filter = window/resolution
- result = filter(x, rep(1/n_filter, n_filter), method = "convolution", sides = 1)
+ result = stats::filter(x, rep(1/n_filter, n_filter), method = "convolution", sides = 1)
class(result) = c("one_box", "ts")
dimnames(result) <- dimnames(x)
return(result)

Contact - Imprint