diff --git a/DESCRIPTION b/DESCRIPTION index d031587fb9a74d58ae86995950ae014ccc40cd10..3711ccb946054e01af6bb7e646a7f562adaff6ca 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,6 +40,7 @@ Collate: 'lifeTable.R' 'makeQxDataFrame.R' 'periodDeathProbabilities.R' + 'plot.valuationTable.R' 'plotValuationTableComparisons.R' 'plotValuationTables.R' 'setLoading.R' diff --git a/NAMESPACE b/NAMESPACE index 67c645de86f340c356490edb2a54c7e9a0e5c712..14f4def03342da21f9bc8602701b1a62ab556493 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +S3method(plot,valuationTable) export(makeQxDataFrame) export(plotValuationTableComparisons) export(plotValuationTables) diff --git a/R/plot.valuationTable.R b/R/plot.valuationTable.R new file mode 100644 index 0000000000000000000000000000000000000000..50d87d91ea0fd6fe2bd2a69433e6c89f6081bcf6 --- /dev/null +++ b/R/plot.valuationTable.R @@ -0,0 +1,52 @@ +#' 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, ...) + } +} + diff --git a/man/plot.valuationTable.Rd b/man/plot.valuationTable.Rd new file mode 100644 index 0000000000000000000000000000000000000000..fcc9a849e1af72a2631dd04140504265b777fb50 --- /dev/null +++ b/man/plot.valuationTable.Rd @@ -0,0 +1,61 @@ +% 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}} +} +