Skip to content
Snippets Groups Projects
Commit 06b21047 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Implement plot.valuationTable as an S3 method

Calls either plotValuationTables or plotValuationTablesCmparison, depending on whether the reference param was used
parent d914a0b3
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,7 @@ Collate: ...@@ -40,6 +40,7 @@ Collate:
'lifeTable.R' 'lifeTable.R'
'makeQxDataFrame.R' 'makeQxDataFrame.R'
'periodDeathProbabilities.R' 'periodDeathProbabilities.R'
'plot.valuationTable.R'
'plotValuationTableComparisons.R' 'plotValuationTableComparisons.R'
'plotValuationTables.R' 'plotValuationTables.R'
'setLoading.R' 'setLoading.R'
......
# Generated by roxygen2: do not edit by hand # Generated by roxygen2: do not edit by hand
S3method(plot,valuationTable)
export(makeQxDataFrame) export(makeQxDataFrame)
export(plotValuationTableComparisons) export(plotValuationTableComparisons)
export(plotValuationTables) export(plotValuationTables)
......
#' Plot multiple valuation tables (life tables) in one plot
#'
#' \code{plot.valuationTable} displays multiple life tables (objects of child
#' classes of \code{valuationTable}) in one plot, with a legend showing the
#' names of the tables. If the argument \code{reference} not given, all
#' mortality rates are plotted on a log-linear scale for comparison. If the
#' argument \code{reference} is given and is a valid life table, then all
#' death probabilities are scaled by the given reference table and the y-axis
#' shows the death rates as percentage of the reference table.
#'
#' @param data First life table to be plotted. Must be a \code{valuationTable} object for the dispatcher to call this function
#' @param ... Additional life tables to be plotted (\code{valuationTable} objects)
#' @param xlim X-axis limitatation (as a two-element vector)
#' @param ylim Y-axis limitatation (as a two-element vector)
#' @param xlab X-axis label (default: "Alter")
#' @param ylab Y-axis label (default: "Sterbewahrscheinlichkeit q_x")
#' @param title The plot title
#' @param legend.position The position of the legend (default is \code{c(0.9,0.1)})
#' @param legend.key.width The keywith of the lines in the legend (default is \code{unit(25,"mm")})
#'
#' @examples
#' # Load the Austrian census data
#' valuationTables.load("Austria_Census")
#'
#' # Plot some select census tables in a log-linear plot
#' plot(mort.AT.census.1869.male, mort.AT.census.1869.female,
#' mort.AT.census.1971.male, mort.AT.census.1971.female,
#' mort.AT.census.2011.male, mort.AT.census.2011.female,
#' title="Austrian census tables",
#' ylab=expression(q[x]), xlab="Age",
#' xlim=c(0,90),
#' legend.position=c(0.95,0.05))
#'
#' # Compare some census tables with the mortality of 2011 Austrian males
#' plot(mort.AT.census.1869.male, mort.AT.census.1869.female,
#' mort.AT.census.1971.male, mort.AT.census.1971.female,
#' mort.AT.census.2011.male, mort.AT.census.2011.female,
#' title="Austrian Census tables, relative to 2011 males",
#' reference=mort.AT.census.2011.male)
#'
#' @seealso \code{\link{plotValuationTables}} and \code{\link{plotValuationTableComparisons}}
#'
#' @import scales
#' @export
plot.valuationTable = function(data, ..., reference=NULL) {
if (!missing(reference) && !is.null(reference)) {
plotValuationTableComparisons(data, ..., reference=reference)
} else {
plotValuationTables(data, ...)
}
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot.valuationTable.R
\name{plot.valuationTable}
\alias{plot.valuationTable}
\title{Plot multiple valuation tables (life tables) in one plot}
\usage{
\method{plot}{valuationTable}(data, ..., reference = NULL)
}
\arguments{
\item{data}{First life table to be plotted. Must be a \code{valuationTable} object for the dispatcher to call this function}
\item{...}{Additional life tables to be plotted (\code{valuationTable} objects)}
\item{xlim}{X-axis limitatation (as a two-element vector)}
\item{ylim}{Y-axis limitatation (as a two-element vector)}
\item{xlab}{X-axis label (default: "Alter")}
\item{ylab}{Y-axis label (default: "Sterbewahrscheinlichkeit q_x")}
\item{title}{The plot title}
\item{legend.position}{The position of the legend (default is \code{c(0.9,0.1)})}
\item{legend.key.width}{The keywith of the lines in the legend (default is \code{unit(25,"mm")})}
}
\description{
\code{plot.valuationTable} displays multiple life tables (objects of child
classes of \code{valuationTable}) in one plot, with a legend showing the
names of the tables. If the argument \code{reference} not given, all
mortality rates are plotted on a log-linear scale for comparison. If the
argument \code{reference} is given and is a valid life table, then all
death probabilities are scaled by the given reference table and the y-axis
shows the death rates as percentage of the reference table.
}
\examples{
# Load the Austrian census data
valuationTables.load("Austria_Census")
# Plot some select census tables in a log-linear plot
plot(mort.AT.census.1869.male, mort.AT.census.1869.female,
mort.AT.census.1971.male, mort.AT.census.1971.female,
mort.AT.census.2011.male, mort.AT.census.2011.female,
title="Austrian census tables",
ylab=expression(q[x]), xlab="Age",
xlim=c(0,90),
legend.position=c(0.95,0.05))
# Compare some census tables with the mortality of 2011 Austrian males
plot(mort.AT.census.1869.male, mort.AT.census.1869.female,
mort.AT.census.1971.male, mort.AT.census.1971.female,
mort.AT.census.2011.male, mort.AT.census.2011.female,
title="Austrian Census tables, relative to 2011 males",
reference=mort.AT.census.2011.male)
}
\seealso{
\code{\link{plotValuationTables}} and \code{\link{plotValuationTableComparisons}}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment