Commit 19372520 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

plotMortalityTables: Re-format (style); ignore qx==0; add legend.justification...

plotMortalityTables: Re-format (style); ignore qx==0; add legend.justification as argument; Remove pathetic attempt at being smarter than R for x-axis breaks
parent 5bbe97cc
...@@ -14,20 +14,28 @@ ...@@ -14,20 +14,28 @@
#' #'
#' @import scales #' @import scales
#' @export #' @export
plotMortalityTables = function(data, ..., legend.title = "Sterbetafel", xlim=NULL, ylim=NULL, xlab=NULL, ylab=NULL, title = "", legend.position=c(0.9,0.1), legend.key.width = unit(25, "mm")) { plotMortalityTables = function(
if (!is.data.frame(data)) { data, ...,
data = makeQxDataFrame(data, ...); legend.title = "Sterbetafel",
} xlim=NULL, ylim=NULL,
if (missing(xlab)) xlab="Alter"; xlab=NULL, ylab=NULL,
if (missing(ylab)) ylab=expression(paste("Sterbewahrscheinlichkeit ", q[x])); title = "",
legend.position = c(0.9,0.1), legend.justification = c(1, 0),
legend.key.width = unit(25, "mm")
) {
if (!is.data.frame(data)) {
data = makeQxDataFrame(data, ...);
}
if (missing(xlab)) xlab = "Alter";
if (missing(ylab)) ylab = expression(paste("Sterbewahrscheinlichkeit ", q[x]));
pl = ggplot(data, aes(x = x, y = y, colour = group, shape = group)) + pl = ggplot(data %>% filter(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"),
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,
...@@ -43,7 +51,7 @@ plotMortalityTables = function(data, ..., legend.title = "Sterbetafel", xlim=NUL ...@@ -43,7 +51,7 @@ plotMortalityTables = function(data, ..., legend.title = "Sterbetafel", xlim=NUL
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))
......
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