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

plotMortalityTAbleComparisons: Add ages, legend.justification arguments;...

plotMortalityTAbleComparisons: Add ages, legend.justification arguments; disable x-axis breaks (i.e. let R choose the proper labels)
parent 3300c30f
No related branches found
No related tags found
No related merge requests found
...@@ -9,10 +9,12 @@ ...@@ -9,10 +9,12 @@
#' @export #' @export
plotMortalityTableComparisons = function( plotMortalityTableComparisons = function(
data, ..., data, ...,
ages = NULL,
xlim = NULL, ylim = NULL, xlim = NULL, ylim = NULL,
xlab = NULL, ylab = NULL, xlab = NULL, ylab = NULL,
title = "", 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"),
reference = NULL) reference = NULL)
{ {
# If no reference mortality table is given, use the first table (data if its a mortality table) # If no reference mortality table is given, use the first table (data if its a mortality table)
...@@ -24,7 +26,10 @@ plotMortalityTableComparisons = function( ...@@ -24,7 +26,10 @@ plotMortalityTableComparisons = function(
} }
} }
if (!is.data.frame(data)) { if (!is.data.frame(data)) {
data = makeQxDataFrame(data, ..., reference=reference); data = makeQxDataFrame(data, ..., reference = reference);
}
if (!is.null(ages)) {
data = data[data$x %in% ages,]
} }
if (missing(xlab)) xlab = "Alter"; if (missing(xlab)) xlab = "Alter";
if (missing(ylab)) { if (missing(ylab)) {
...@@ -39,7 +44,7 @@ plotMortalityTableComparisons = function( ...@@ -39,7 +44,7 @@ plotMortalityTableComparisons = function(
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,0), 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,
...@@ -57,7 +62,7 @@ plotMortalityTableComparisons = function( ...@@ -57,7 +62,7 @@ plotMortalityTableComparisons = function(
scale_x_continuous( scale_x_continuous(
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))
......
...@@ -10,12 +10,15 @@ ...@@ -10,12 +10,15 @@
#' @param ylab Y-axis label (default: "Sterbewahrscheinlichkeit q_x relativ zu ....") #' @param ylab Y-axis label (default: "Sterbewahrscheinlichkeit q_x relativ zu ....")
#' @param title The plot title #' @param title The plot title
#' @param legend.position The position of the legend (default is \code{c(0.9,0.1)}) #' @param legend.position The position of the legend (default is \code{c(0.9,0.1)})
#' @param legend.justification The justification of the legend (default is \code{c(1,)})
#' @param legend.key.width The keywith of the lines in the legend (default is \code{unit(25,"mm")}) #' @param legend.key.width The keywith of the lines in the legend (default is \code{unit(25,"mm")})
#' @param ages Plot only the given ages
#' #'
#' @import scales #' @import scales
#' @export #' @export
plotMortalityTables = function( plotMortalityTables = function(
data, ..., data, ...,
ages = NULL,
legend.title = "Sterbetafel", legend.title = "Sterbetafel",
xlim=NULL, ylim=NULL, xlim=NULL, ylim=NULL,
xlab=NULL, ylab=NULL, xlab=NULL, ylab=NULL,
...@@ -29,7 +32,11 @@ plotMortalityTables = function( ...@@ -29,7 +32,11 @@ 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(subset(data, y > 0), aes(x = x, y = y, colour = group, shape = group)) + data = subset(data, y > 0)
if (!is.null(ages)) {
data = data[data$x %in% ages,]
}
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"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment