aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2016-06-25 19:36:16 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2016-06-25 19:36:16 +0200
commit693beea972cad4633c1d8baf422913ff3e8d709d (patch)
treec0ff57be6b9200e1984782e062e2a979db09c872
parente8392a8e110bb1957adc9e2047642f9387ff83db (diff)
Now the old behaviour is restored for compatibility reasons
When observed variables are not shown in separate plots, the residual plot is shown in the lower third of the total plotting area
-rw-r--r--NEWS.md4
-rw-r--r--R/plot.mkinfit.R27
-rw-r--r--man/plot.mkinfit.Rd11
3 files changed, 26 insertions, 16 deletions
diff --git a/NEWS.md b/NEWS.md
index c4b74b4a..9148371d 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -6,9 +6,7 @@
- The title was changed to `Kinetic evaluations of chemical degradation data`
-- `plot.mkinfit`: If a residual plot is requested, show it next to the plot of the fit, not below. This may cause existing code to produce bad-looking plots, but was done to make the next feature possible without increasing code complexity too much.
-
-- `plot.mkinfit`: Add the possibility to show fits and residual plots separately for the observed variables
+- `plot.mkinfit`: Add the possibility to show fits (and residual plots if requested) separately for the observed variables
- The main vignette `mkin` was converted to R markdown and updated
diff --git a/R/plot.mkinfit.R b/R/plot.mkinfit.R
index 6bc64351..317c74a3 100644
--- a/R/plot.mkinfit.R
+++ b/R/plot.mkinfit.R
@@ -68,16 +68,22 @@ plot.mkinfit <- function(x, fit = x,
# Layout should be restored afterwards
oldpar <- par(no.readonly = TRUE)
- n_plot_cols = if (show_residuals) 2 else 1
- n_plots = n_plot_rows * n_plot_cols
-
- # Set relative plot heights, so the first and the last plot are the norm
- # and the middle plots (if n_plot_rows >2) are smaller by rel.height.middle
- rel.heights <- if (n_plot_rows > 2) c(1, rep(rel.height.middle, n_plot_rows - 2), 1)
- else rep(1, n_plot_rows)
- layout_matrix = matrix(1:n_plots,
- n_plot_rows, n_plot_cols, byrow = TRUE)
- layout(layout_matrix, heights = rel.heights)
+ # If the observed variables are shown separately, do row layout
+ if (sep_obs) {
+ n_plot_cols = if (show_residuals) 2 else 1
+ n_plots = n_plot_rows * n_plot_cols
+
+ # Set relative plot heights, so the first and the last plot are the norm
+ # and the middle plots (if n_plot_rows >2) are smaller by rel.height.middle
+ rel.heights <- if (n_plot_rows > 2) c(1, rep(rel.height.middle, n_plot_rows - 2), 1)
+ else rep(1, n_plot_rows)
+ layout_matrix = matrix(1:n_plots,
+ n_plot_rows, n_plot_cols, byrow = TRUE)
+ layout(layout_matrix, heights = rel.heights)
+ } else { # else show residuals in the lower third to keep compatibility
+ layout(matrix(c(1, 2), 2, 1), heights = c(2, 1.3))
+ par(mar = c(3, 4, 4, 2) + 0.1)
+ }
}
# Replicate legend position argument if necessary
@@ -129,6 +135,7 @@ plot.mkinfit <- function(x, fit = x,
if (show_residuals) {
residuals <- subset(fit$data, variable %in% row_obs_vars, residual)
if (maxabs == "auto") maxabs = max(abs(residuals), na.rm = TRUE)
+ if (!sep_obs) par(mar = c(5, 4, 0, 2) + 0.1)
plot(0, type="n",
xlim = xlim,
ylim = c(-1.2 * maxabs, 1.2 * maxabs),
diff --git a/man/plot.mkinfit.Rd b/man/plot.mkinfit.Rd
index b80928f7..00b2eca5 100644
--- a/man/plot.mkinfit.Rd
+++ b/man/plot.mkinfit.Rd
@@ -61,14 +61,18 @@
Should a legend be added to the plot?
}
\item{show_residuals}{
- Should residuals be shown in the lower third of the plot?
+ Should residuals be shown? If only one plot of the fits is shown, the
+ residual plot is in the lower third of the plot? Otherwise, i.e. if
+ "sep_obs" is given, the residual plots will be located to the right of
+ the plots of the fitted curves.
}
\item{maxabs}{
Maximum absolute value of the residuals. This is used for the scaling of
the y axis and defaults to "auto".
}
\item{sep_obs}{
- Should the observed variables be shown in separate subplots?
+ Should the observed variables be shown in separate subplots? If yes, residual plots
+ requested by "show_residuals" will be shown next to, not below the plot of the fits.
}
\item{rel.height.middle}{
The relative height of the middle plot, if more than two rows of plots are shown.
@@ -94,9 +98,10 @@ SFO_SFO <- mkinmod(parent = mkinsub("SFO", "m1", full = "Parent"),
m1 = mkinsub("SFO", full = "Metabolite M1" ))
fit <- mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE, method.modFit = "Marq")
plot(fit)
+plot(fit, show_residuals = TRUE)
# Show the observed variables separately
-plot(fit, sep_obs = TRUE)
+plot(fit, sep_obs = TRUE, lpos = c("topright", "bottomright"))
# Show the observed variables separately, with residuals
plot(fit, sep_obs = TRUE, show_residuals = TRUE, lpos = c("topright", "bottomright"))

Contact - Imprint