Skip to content

Commit

Permalink
Include col argument in residual plotting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
amvillegas committed Feb 9, 2016
1 parent 4c48aaf commit 0e3260f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ importFrom(graphics,image.default)
importFrom(graphics,lines)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(methods,hasArg)
importFrom(rootSolve,multiroot)
importFrom(stats,aggregate)
importFrom(stats,as.formula)
Expand Down
1 change: 0 additions & 1 deletion R/docStMoMo.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#' @importFrom stats rpois runif start
#' @importFrom utils head tail
#' @importFrom RColorBrewer brewer.pal
#' @importFrom methods hasArg
NULL


Expand Down
17 changes: 13 additions & 4 deletions R/residualsfitStMoMo.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ residuals.fitStMoMo <- function(object, scale = TRUE, ...) {
#' "signplot"),
#' reslim = NULL, plotAge = TRUE,
#' plotYear = TRUE, plotCohort = TRUE,
#' pch = 20, ...)
#' pch = 20, col = NULL, ...)
#'
#' @param x an object of class \code{resStMoMo} with the residuals of a
#' Stochastic Mortality Model.
Expand All @@ -84,6 +84,11 @@ residuals.fitStMoMo <- function(object, scale = TRUE, ...) {
#' @param pch optional symbol to use for the points in a scatterplot.
#' This is only used when \code{type = "scatter"}. See
#' \code{\link[graphics]{plot}}.
#' @param col optional colours to use in plotting. If
#' \code{type = "scatter"} this is a single colour to use in the points
#' in the scatter plots, while if \code{type = "colourmap"} this should
#' be a list of colours (see help in \code{\link[fields]{image.plot}}
#' for details). This argument is ignored if \code{type = "signplot"}.
#' @param ... other plotting parameters to be passed to the plotting
#' functions. This can be used to control the appearance of the plots.
#'
Expand Down Expand Up @@ -116,23 +121,27 @@ residuals.fitStMoMo <- function(object, scale = TRUE, ...) {
#' @method plot resStMoMo
plot.resStMoMo <- function(x, type = c("scatter", "colourmap", "signplot"),
reslim = NULL, plotAge = TRUE, plotYear = TRUE,
plotCohort = TRUE, pch = 20, ...) {
plotCohort = TRUE, pch = 20, col = NULL, ...) {
type <- match.arg(type)
oldpar <- par(no.readonly = TRUE)

if (is.null(reslim)) {
maxRes <- max(abs(x$residuals), na.rm = TRUE)
reslim <- c(-maxRes, maxRes)
}
if (!hasArg(col)) {
if (is.null(col) & type == "colourmap") {
col <- colorRampPalette(RColorBrewer::brewer.pal(10, "RdBu"))(64)
}
if (is.null(col) & type == "scatter") {
col <- "black"
}

switch(type,
scatter = scatterplotAPC(x$residuals, x$ages, x$years,
plotAge = plotAge, plotYear = plotYear,
plotCohort = plotCohort, pch = pch,
ylab = "residuals", ylim = reslim, ...),
ylab = "residuals", ylim = reslim,
col = col, ...),
colourmap = fields::image.plot(x$year, x$age, t(x$residuals),
zlim = reslim, ylab = "age",
xlab = "calendar year", col = col,
Expand Down
8 changes: 7 additions & 1 deletion man/plot.resStMoMo.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"signplot"),
reslim = NULL, plotAge = TRUE,
plotYear = TRUE, plotCohort = TRUE,
pch = 20, ...)
pch = 20, col = NULL, ...)
}
\arguments{
\item{x}{an object of class \code{resStMoMo} with the residuals of a
Expand All @@ -33,6 +33,12 @@ should be produced. This is only used when \code{type = "scatter"}.}
This is only used when \code{type = "scatter"}. See
\code{\link[graphics]{plot}}.}

\item{col}{optional colours to use in plotting. If
\code{type = "scatter"} this is a single colour to use in the points
in the scatter plots, while if \code{type = "colourmap"} this should
be a list of colours (see help in \code{\link[fields]{image.plot}}
for details). This argument is ignored if \code{type = "signplot"}.}

\item{...}{other plotting parameters to be passed to the plotting
functions. This can be used to control the appearance of the plots.}
}
Expand Down

0 comments on commit 0e3260f

Please sign in to comment.