diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2023-03-22 07:49:39 +0100 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2023-03-22 07:49:39 +0100 |
commit | 81bb17f887f192a5ee4f77829a65689934776471 (patch) | |
tree | 2f8560bb50983696ad278480b430c8349961cf9f /R | |
parent | 28286eeaca84c85d2f4c3cddc9524d56d23b9aa0 (diff) |
Fix plotting saemix without covariates, polish
Better linetypes and labels
Diffstat (limited to 'R')
-rw-r--r-- | R/plot.mixed.mmkin.R | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/R/plot.mixed.mmkin.R b/R/plot.mixed.mmkin.R index 68f8d577..466e55fc 100644 --- a/R/plot.mixed.mmkin.R +++ b/R/plot.mixed.mmkin.R @@ -13,7 +13,9 @@ utils::globalVariables("ds") #' In case there is a covariate model, the behaviour depends on the value #' of 'covariates' #' @param covariates Data frame with covariate values for all variables in -#' any covariate models in the object. If given, it overrides 'covariate_quantiles' +#' any covariate models in the object. If given, it overrides 'covariate_quantiles'. +#' Each line in the data frame will result in a line drawn for the population. +#' Rownames are used in the legend to label the lines. #' @param covariate_quantiles This argument only has an effect if the fitted #' object has covariate models. If so, the default is to show three population #' curves, for the 5th percentile, the 50th percentile and the 95th percentile @@ -77,7 +79,7 @@ plot.mixed.mmkin <- function(x, obs_vars = names(x$mkinmod$map), standardized = TRUE, covariates = NULL, - covariate_quantiles = c(0.05, 0.5, 0.95), + covariate_quantiles = c(0.5, 0.05, 0.95), xlab = "Time", xlim = range(x$data$time), resplot = c("predicted", "time"), @@ -151,6 +153,10 @@ plot.mixed.mmkin <- function(x, covariates = as.data.frame( apply(x$covariates, 2, quantile, covariate_quantiles, simplify = FALSE)) + rownames(covariates) <- paste( + ifelse(length(x$covariate_models) == 1, + "Covariate", "Covariates"), + rownames(covariates)) } degparms_pop <- parms(x, covariates = covariates) pop_curves <- TRUE @@ -160,9 +166,10 @@ plot.mixed.mmkin <- function(x, } } - # Make sure degparms_pop is a matrix, population curve variants in columns, if any + # Make sure degparms_pop is a matrix, columns corresponding to population curve(s) if (is.null(dim(degparms_pop))) { - degparms_pop <- matrix(degparms_pop) + degparms_pop <- matrix(degparms_pop, ncol = 1, + dimnames = list(names(degparms_pop), "Population")) } degparms_fixed <- fit_1$fixed$value |