Commit b64e75b5 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

Add "ages" and "legend.justification" arguments to plotMortalityTrend; Allow...

Add "ages" and "legend.justification" arguments to plotMortalityTrend; Allow list of tables to be passed to makeMortalitytTrendDataFrame (and plotMortalityTrend)
parent ae87c335
...@@ -34,10 +34,22 @@ ...@@ -34,10 +34,22 @@
#' Period = 2030, title = "Trends of Austrian Annuity Tables for Period 2030") #' Period = 2030, title = "Trends of Austrian Annuity Tables for Period 2030")
#'#' @import scales #'#' @import scales
#' @export #' @export
plotMortalityTrend = function(data, ..., xlim=NULL, ylim=NULL, xlab=NULL, ylab=NULL, title = "", legend.position=c(0.9,0.9), legend.key.width = unit(25, "mm")) { plotMortalityTrend = function(
data, ...,
ages = NULL,
xlim=NULL, ylim=NULL,
xlab=NULL, ylab=NULL,
title = "",
legend.position=c(0.9, 0.9), legend.justification = c(1, 1),
legend.key.width = unit(25, "mm")
) {
if (!is.data.frame(data)) { if (!is.data.frame(data)) {
data = makeMortalityTrendDataFrame(data, ...); data = makeMortalityTrendDataFrame(data, ...);
} }
if (!is.null(ages)) {
data = data[data$x %in% ages,]
}
if (missing(xlab)) xlab = "Alter"; if (missing(xlab)) xlab = "Alter";
if (missing(ylab)) ylab = expression(paste("Sterblichkeitstrend ", lambda[x])); if (missing(ylab)) ylab = expression(paste("Sterblichkeitstrend ", lambda[x]));
...@@ -47,7 +59,7 @@ plotMortalityTrend = function(data, ..., xlim=NULL, ylim=NULL, xlab=NULL, ylab=N ...@@ -47,7 +59,7 @@ plotMortalityTrend = function(data, ..., xlim=NULL, ylim=NULL, xlab=NULL, ylab=N
plot.title = element_text(size = 18, face = "bold"), plot.title = element_text(size = 18, face = "bold"),
legend.title = element_text(size = 14, face = "bold.italic"), legend.title = element_text(size = 14, face = "bold.italic"),
# legend in bottom right corner of the plot # legend in bottom right corner of the plot
legend.justification = c(1,1), legend.position = legend.position, legend.justification = legend.justification, legend.position = legend.position,
# No box around legend entries # No box around legend entries
legend.key = element_blank(), legend.key = element_blank(),
legend.key.width = legend.key.width, legend.key.width = legend.key.width,
...@@ -78,7 +90,7 @@ plotMortalityTrend = function(data, ..., xlim=NULL, ylim=NULL, xlab=NULL, ylab=N ...@@ -78,7 +90,7 @@ plotMortalityTrend = function(data, ..., xlim=NULL, ylim=NULL, xlab=NULL, ylab=N
makeMortalityTrendDataFrame = function(..., YOB = 1972, Period = NULL) { makeMortalityTrendDataFrame = function(..., YOB = 1972, Period = NULL) {
# If reference is given, normalize all probabilities by that table! # If reference is given, normalize all probabilities by that table!
data = list(...); data = unlist(list(...));
names(data) = lapply(data, function(t) t@name); names(data) = lapply(data, function(t) t@name);
if (missing(Period) || is.null(Period)) { if (missing(Period) || is.null(Period)) {
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
\alias{plotMortalityTrend} \alias{plotMortalityTrend}
\title{Plot the trends of multiple mortality tables (life tables) in one chart} \title{Plot the trends of multiple mortality tables (life tables) in one chart}
\usage{ \usage{
plotMortalityTrend(data, ..., xlim = NULL, ylim = NULL, xlab = NULL, plotMortalityTrend(data, ..., ages = NULL, xlim = NULL, ylim = NULL,
ylab = NULL, title = "", legend.position = c(0.9, 0.9), xlab = NULL, ylab = NULL, title = "", legend.position = c(0.9, 0.9),
legend.key.width = unit(25, "mm")) legend.justification = c(1, 1), legend.key.width = unit(25, "mm"))
} }
\arguments{ \arguments{
\item{data}{First life table to be plotted. Either a \code{data.frame} generated by \code{makeQxDataFrame} or a \code{mortalityTable} object} \item{data}{First life table to be plotted. Either a \code{data.frame} generated by \code{makeQxDataFrame} or a \code{mortalityTable} object}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment