Commit 4a0365b6 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

Fix error: use subset function rather than filter from dplyr (which is not a...

Fix error: use subset function rather than filter from dplyr (which is not a dependency); Style fixes
parent 19372520
...@@ -20,7 +20,7 @@ setMethod("commutationNumbers", "mortalityTable", ...@@ -20,7 +20,7 @@ setMethod("commutationNumbers", "mortalityTable",
function(object, ..., i = 0.03) { function(object, ..., i = 0.03) {
ages = ages(object, ...) ages = ages(object, ...)
qx = deathProbabilities(object, ...) qx = deathProbabilities(object, ...)
commutationNumbers(qx, ages, i) commutationNumbers(qx, ages = ages, i = i)
}) })
...@@ -30,7 +30,7 @@ setMethod("commutationNumbers", "mortalityTable", ...@@ -30,7 +30,7 @@ setMethod("commutationNumbers", "mortalityTable",
#' Return value is a list of data frames #' Return value is a list of data frames
setMethod("commutationNumbers", "numeric", setMethod("commutationNumbers", "numeric",
function(object, ages, i = 0.03) { function(object, ages, i = 0.03) {
v = 1/(1 + i) v = 1 / (1 + i)
qx = object qx = object
lx = cumprod(c(100000, 1 - object[-length(object)])) lx = cumprod(c(100000, 1 - object[-length(object)]))
dx = -diff(c(lx, 0)) dx = -diff(c(lx, 0))
...@@ -53,7 +53,7 @@ setMethod("commutationNumbers", "pensionTable", ...@@ -53,7 +53,7 @@ setMethod("commutationNumbers", "pensionTable",
probs = transitionProbabilities(object, ...) probs = transitionProbabilities(object, ...)
ages = probs$x ages = probs$x
list( list(
q = commutationNumbers(probs$q + probs$i, ages = ages, i = i), q = commutationNumbers(probs$q + probs$i, ages = ages, i = i),
qi = commutationNumbers(probs$qi, ages = ages, i = i), qi = commutationNumbers(probs$qi, ages = ages, i = i),
qp = commutationNumbers(probs$qp, ages = ages, i = i), qp = commutationNumbers(probs$qp, ages = ages, i = i),
qw = commutationNumbers(probs$qw, ages = ages, i = i), qw = commutationNumbers(probs$qw, ages = ages, i = i),
......
...@@ -29,7 +29,7 @@ plotMortalityTables = function( ...@@ -29,7 +29,7 @@ plotMortalityTables = function(
if (missing(xlab)) xlab = "Alter"; if (missing(xlab)) xlab = "Alter";
if (missing(ylab)) ylab = expression(paste("Sterbewahrscheinlichkeit ", q[x])); if (missing(ylab)) ylab = expression(paste("Sterbewahrscheinlichkeit ", q[x]));
pl = ggplot(data %>% filter(y>0), aes(x = x, y = y, colour = group, shape = group)) + pl = ggplot(subset(data, y > 0), aes(x = x, y = y, colour = group, shape = group)) +
theme_bw() + theme_bw() +
theme( theme(
plot.title = element_text(size = 18, face = "bold"), plot.title = element_text(size = 18, face = "bold"),
...@@ -39,7 +39,7 @@ plotMortalityTables = function( ...@@ -39,7 +39,7 @@ plotMortalityTables = function(
# 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,
legend.background = element_rect(colour="gray50", linetype="solid") legend.background = element_rect(colour = "gray50", linetype = "solid")
) + ) +
geom_line(na.rm = TRUE) + geom_line(na.rm = TRUE) +
scale_y_log10( scale_y_log10(
...@@ -52,13 +52,13 @@ plotMortalityTables = function( ...@@ -52,13 +52,13 @@ plotMortalityTables = function(
name = xlab, name = xlab,
#breaks = function (limits) scales::trans_breaks('', function(x) 10^x), #breaks = function (limits) scales::trans_breaks('', function(x) 10^x),
# breaks = function (limits) seq(max(min(limits),0),max(limits),5), # breaks = function (limits) seq(max(min(limits),0),max(limits),5),
minor_breaks = function (limits) seq(max(round(min(limits)),0),round(max(limits)),1) minor_breaks = function(limits) seq(max(round(min(limits)), 0), round(max(limits)), 1)
#labels = scales::trans_format('log10', scales::math_format(10^.x)) #labels = scales::trans_format('log10', scales::math_format(10^.x))
) + ) +
coord_cartesian(xlim=xlim, ylim=ylim) + coord_cartesian(xlim = xlim, ylim = ylim) +
annotation_logticks(sides="lr") + annotation_logticks(sides = "lr") +
xlab("Alter") + labs(colour=legend.title, shape=legend.title); xlab("Alter") + labs(colour = legend.title, shape = legend.title);
if (title != "") { if (title != "") {
pl = pl + ggtitle(title); pl = pl + ggtitle(title);
} }
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
\usage{ \usage{
plotMortalityTables(data, ..., legend.title = "Sterbetafel", xlim = NULL, plotMortalityTables(data, ..., legend.title = "Sterbetafel", xlim = NULL,
ylim = NULL, xlab = NULL, ylab = NULL, title = "", ylim = NULL, xlab = NULL, ylab = NULL, title = "",
legend.position = c(0.9, 0.1), legend.key.width = unit(25, "mm")) legend.position = c(0.9, 0.1), legend.justification = c(1, 0),
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