From 4a91212601c379498202f8a5cecdee085f2cbe0a Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Sat, 26 Apr 2014 08:42:29 +0200 Subject: Fix the default case for obs_vars in plot.mkinfit() --- R/plot.mkinfit.R | 16 +++++----------- man/plot.mkinfit.Rd | 5 +++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/R/plot.mkinfit.R b/R/plot.mkinfit.R index 2b85977..80cf45f 100644 --- a/R/plot.mkinfit.R +++ b/R/plot.mkinfit.R @@ -18,7 +18,7 @@ if(getRversion() >= '2.15.1') utils::globalVariables(c("type", "variable", "observed")) plot.mkinfit <- function(x, fit = x, - obs_vars = vector(), + obs_vars = names(fit$mkinmod$map), xlab = "Time", ylab = "Observed", xlim = range(fit$data$time), ylim = c(0, max(subset(fit$data, variable %in% obs_vars)$observed, na.rm = TRUE)), @@ -31,12 +31,6 @@ plot.mkinfit <- function(x, fit = x, solution_type = fit$solution_type parms.all <- c(fit$bparms.optim, fit$bparms.fixed) - obs_vars_all <- names(fit$mkinmod$map) - - if (length(obs_vars) > 0){ - vars <- intersect(obs_vars_all, obs_vars) - } else vars <- obs_vars_all - ininames <- c( rownames(subset(fit$start, type == "state")), rownames(subset(fit$fixed, type == "state"))) @@ -64,13 +58,13 @@ plot.mkinfit <- function(x, fit = x, } # Plot the data and model output names(col_obs) <- names(pch_obs) <- names(lty_obs) <- names(fit$mkinmod$map) - for (obs_var in vars) { + for (obs_var in obs_vars) { points(subset(fit$data, variable == obs_var, c(time, observed)), pch = pch_obs[obs_var], col = col_obs[obs_var]) } - matlines(out$time, out[vars], col = col_obs[vars], lty = lty_obs[vars]) + matlines(out$time, out[obs_vars], col = col_obs[obs_vars], lty = lty_obs[obs_vars]) if (legend == TRUE) { - legend(lpos, inset= inset, legend = vars, - col = col_obs[vars], pch = pch_obs[vars], lty = lty_obs[vars]) + legend(lpos, inset= inset, legend = obs_vars, + col = col_obs[obs_vars], pch = pch_obs[obs_vars], lty = lty_obs[obs_vars]) } } diff --git a/man/plot.mkinfit.Rd b/man/plot.mkinfit.Rd index 41682ad..4ae82a5 100644 --- a/man/plot.mkinfit.Rd +++ b/man/plot.mkinfit.Rd @@ -10,7 +10,7 @@ } \usage{ \method{plot}{mkinfit}(x, fit = x, - obs_vars = vector(), + obs_vars = names(fit$mkinmod$map), xlab = "Time", ylab = "Observed", xlim = range(fit$data$time), ylim = c(0, max(fit$data$observed, na.rm = TRUE)), col_obs = 1:length(fit$mkinmod$map), pch_obs = col_obs, @@ -26,7 +26,8 @@ } \item{obs_vars}{ A character vector of names of the observed variables for which the - data and the model should be plotted. + data and the model should be plotted. Defauls to all observed variables + in the model. } \item{xlab}{ label for the x axis. -- cgit v1.2.1