Skip to content

Commit

Permalink
Merge pull request #17 from kassambara/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
pbiecek authored Jun 20, 2017
2 parents d09e655 + 0ba10bc commit dabe9cc
Show file tree
Hide file tree
Showing 131 changed files with 451 additions and 553 deletions.
9 changes: 3 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: survminer
Type: Package
Title: Drawing Survival Curves using 'ggplot2'
Version: 0.3.1.999
Date: 2017-03-21
Version: 0.4.0.999
Date: 2017-06-07
Authors@R: c(
person("Alboukadel", "Kassambara", role = c("aut", "cre"), email = "alboukadel.kassambara@gmail.com"),
person("Marcin", "Kosinski", role = c("aut"), email = "m.p.kosinski@@gmail.com"),
Expand All @@ -16,7 +16,7 @@ License: GPL-2
LazyData: TRUE
Depends:
ggplot2,
ggpubr(>= 0.1.2)
ggpubr(>= 0.1.3)
Imports:
grid,
gridExtra(>= 2.0),
Expand All @@ -36,8 +36,6 @@ Imports:
Suggests:
knitr,
KMsurv
Remotes:
kassambara/ggpubr
VignetteBuilder: knitr
URL: http://www.sthda.com/english/rpkgs/survminer/
BugReports: https://github.com/kassambara/survminer/issues
Expand Down Expand Up @@ -74,4 +72,3 @@ Collate:
'surv_group_by.R'
'surv_fit.R'
'surv_median.R'
'theme_classic2.R'
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export(surv_group_by)
export(surv_median)
export(surv_pvalue)
export(surv_summary)
export(theme_classic2)
export(theme_cleantable)
export(theme_survminer)
import(broom)
Expand Down
63 changes: 44 additions & 19 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
# survminer 0.3.1.999
# survminer 0.4.0.999

## New features


## Major changes


## Minor changes


## Bug fixes


# survminer 0.4.0

## New features

- New option `test.for.trend` added in `ggsurvplot()` to perform a log-rank test for trend. logical value. Default is FALSE. If TRUE, returns the test for trend p-values. Tests for trend are designed to detect ordered differences in survival curves. That is, for at least one group. The test for trend can be only performed when the number of groups is > 2 ([#188](https://github.com/kassambara/survminer/issues/188)).

- New option `add.all` added now in `ggsurvplot()` to add he survival curves of (all) pooled patients onto the main survival plot stratified by grouping variables. Alias of the `ggsurvplot_add_all()` function ([#194](https://github.com/kassambara/survminer/issues/194)).
### New options in ggsurvplot()


- New argument `test.for.trend` added in `ggsurvplot()` to perform a log-rank test for trend. logical value. Default is FALSE. If TRUE, returns the test for trend p-values. Tests for trend are designed to detect ordered differences in survival curves. That is, for at least one group. The test for trend can be only performed when the number of groups is > 2 ([#188](https://github.com/kassambara/survminer/issues/188)).

- New argument `add.all` added now in `ggsurvplot()` to add he survival curves of (all) pooled patients onto the main survival plot stratified by grouping variables. Alias of the `ggsurvplot_add_all()` function ([#194](https://github.com/kassambara/survminer/issues/194)).

- New option `combine = TRUE` is now available in the `ggsurvplot()` function to combine a list survfit objects on the same plot. Alias of the *ggsurvplot_combine*() function ([#195](https://github.com/kassambara/survminer/issues/195)).
- New argument `combine = TRUE` is now available in the `ggsurvplot()` function to combine a list of survfit objects on the same plot. Alias of the *ggsurvplot_combine*() function ([#195](https://github.com/kassambara/survminer/issues/195)).

- The standard convention of ggplot2 is to have the axes offset from the origin. This can be annoying with Kaplan-Meier plots. New argument `axes.offset` added non in `ggsurvplot()`. logical value. Default is TRUE. If FALSE, set the plot axes to start at the origin (c(0,0)) ([#196](https://github.com/kassambara/survminer/issues/196)).

- The function `ggsurvplot()` can take a list of survfit objects and produces a list of ggsurvplots ([#204](https://github.com/kassambara/survminer/issues/204)).

- New option `facet.by` added now in `ggsurvplot()` to draw multi-panel survival curves of a data set grouped by one or two variables. Alias of the `ggsurvplot_facet()` function ([#205](https://github.com/kassambara/survminer/issues/205)).
- New argument `facet.by` added now in `ggsurvplot()` to draw multi-panel survival curves of a data set grouped by one or two variables. Alias of the `ggsurvplot_facet()` function ([#205](https://github.com/kassambara/survminer/issues/205)).

- New option `group.by` added now in `ggsurvplot()` to create survival curves of grouped data sets. Alias of the `ggsurvplot_group_by()` function.
- New argument `group.by` added now in `ggsurvplot()` to create survival curves of grouped data sets. Alias of the `ggsurvplot_group_by()` function.


- In `ggsurvplot()`, one can specify pval = TRUE/FALSE as a logical value. Now, it's also possible to specify the argument `pval` as a numeric value (e.g.: pval = 0.002), that will be passed to the plot, so that user can pass any custom p-value to the final plot ([@MarcinKosinski, #189](https://github.com/kassambara/survminer/issues/189)) or one can specify it as a character string (e.g.: pval = "p < 0001") ([@MarcinKosinski, #193](https://github.com/kassambara/survminer/issues/193)).


- New argument `xscale` in `ggsurvplot()`: numeric or character value specifying x-axis scale.
- If numeric, the value is used to divide the labels on the x axis. For example, a value of 365.25 will give labels in years instead of the original days.
- If character, allowed options include one of c("d_m", "d_y", "m_d", "m_y", "y_d", "y_m"), where d = days, m = months and y = years. For example, xscale = "d_m" will transform labels from days to months; xscale = "m_y", will transform labels from months to years ([#166](https://github.com/kassambara/survminer/issues/166)).

- New arguments `censor.shape` and `censor.size` to change the shape and the shape of censors ([#186](https://github.com/kassambara/survminer/issues/186) & [#187](https://github.com/kassambara/survminer/issues/187)).


- New argument `conf.int.alpha` added in `ggsurvplot()`. Numeric value specifying fill color transparency. Value should be in [0, 1], where 0 is full transparency and 1 is no transparency.


### New functions

- New function `surv_group_by()` added to create a grouped data set for survival analysis.

- New function `ggsurvplot_df()` added. An extension to ggsurvplot() to plot survival curves from any data frame containing the summary of survival curves as returned the surv_summary() function. Might be useful for a user who wants to use ggsurvplot for visualizing survival curves computed by another method than the standard survfit.formula function. In this case, the user has just to provide the data frame containing the summary of the survival analysis.
Expand All @@ -31,25 +65,14 @@
- group.by option


- In `ggsurvplot()`, one can specify pval = TRUE/FALSE as a logical value. Now, it's also possible to specify the argument `pval` as a numeric value (e.g.: pval = 0.002), that will be passed to the plot, so that user can pass any custom p-value to the final plot ([@MarcinKosinski, #189](https://github.com/kassambara/survminer/issues/189)) or one can specify it as a character string (e.g.: pval = "p < 0001") ([@MarcinKosinski, #193](https://github.com/kassambara/survminer/issues/193)).


- New argument `xscale` in `ggsurvplot()`: numeric or character value specifying x-axis scale.
- If numeric, the value is used to divide the labels on the x axis. For example, a value of 365.25 will give labels in years instead of the original days.
- If character, allowed options include one of c("d_m", "d_y", "m_d", "m_y", "y_d", "y_m"), where d = days, m = months and y = years. For example, xscale = "d_m" will transform labels from days to months; xscale = "m_y", will transform labels from months to years ([#166](https://github.com/kassambara/survminer/issues/166)).

- New arguments `censor.shape` and `censor.size` to change the shape and the shape of censors ([#186](https://github.com/kassambara/survminer/issues/186) & [#187](https://github.com/kassambara/survminer/issues/187)).


- New argument `conf.int.alpha` added in `ggsurvplot()`. Numeric value specifying fill color transparency. Value should be in [0, 1], where 0 is full transparency and 1 is no transparency.

## Major changes

- The `ggforest()` function has changed a lot. Now presents much more statistics for each level of each variable (extracted with `broom::tidy`) and also some statistics for the `coxph` model, like AIC, p.value, concordance (extracted with `broom::glance`) ([#178](https://github.com/kassambara/survminer/issues/178))

## Minor changes
- Now, `ggcompetingrisks()` supports the `add_ci` argument. If `add_ci=TRUE` and `fit` is an object of class `cuminc` then confidence intervals are plotted with `geom_ribbon`.
- Now, `ggcompetingrisks()` supports the `conf.int` argument. If `conf.int=TRUE` and `fit` is an object of class `cuminc` then confidence intervals are plotted with `geom_ribbon`.

- Now, `ggsurvplot()` supports the `survfit()` outputs when used with the argument `start.time`.

Expand Down Expand Up @@ -85,6 +108,8 @@ ggsurv$plot + facet_grid(rx ~ adhere)

- New argument `fun` added in `ggcoxadjustedcurves()` ([@meganli, #202](https://github.com/kassambara/survminer/issues/202)).

- The function `theme_classic2()` removed.

## Bug fixes

- Columns/Rows are now correctly labeled in `pairwise_survdiff`() display ([@mriffle, #212](https://github.com/kassambara/survminer/issues/212)).
Expand Down
18 changes: 9 additions & 9 deletions R/ggcompetingrisks.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#' @param ggtheme function, \code{ggplot2} theme name. Default value is \link{theme_survminer}.
#' Allowed values include ggplot2 official themes: see \code{\link[ggplot2]{theme}}.
#' @param ... further arguments passed to the function \code{\link[ggpubr]{ggpar}} for customizing the plot.
#' @param add_ci if \code{TRUE} then additional layer (\code{geom_ribbon}) is added around the point estimate. The ribon is plotted with boundries +- \code{coef}*standard deviation.
#' @param coef see \code{add_ci}, scaling actor for the ribbon. The default value is 1.96.
#' @param conf.int if \code{TRUE} then additional layer (\code{geom_ribbon}) is added around the point estimate. The ribon is plotted with boundries +- \code{coef}*standard deviation.
#' @param coef see \code{conf.int}, scaling actor for the ribbon. The default value is 1.96.
#' @return Returns an object of class \code{gg}.
#'
#' @author Przemyslaw Biecek, \email{przemyslaw.biecek@@gmail.com}
Expand All @@ -27,8 +27,8 @@
#' print(fit <- cmprsk::cuminc(ss,cc,gg,strt))
#' ggcompetingrisks(fit)
#' ggcompetingrisks(fit, multiple_panels = FALSE)
#' ggcompetingrisks(fit, add_ci = TRUE)
#' ggcompetingrisks(fit, multiple_panels = FALSE, add_ci = TRUE)
#' ggcompetingrisks(fit, conf.int = TRUE)
#' ggcompetingrisks(fit, multiple_panels = FALSE, conf.int = TRUE)
#'
#' # handles survfitms objects
#' library(survival)
Expand All @@ -47,13 +47,13 @@
ggcompetingrisks <- function(fit, gnames = NULL, gsep=" ",
multiple_panels = TRUE,
ggtheme = theme_survminer(),
coef = 1.96, add_ci = FALSE, ...) {
coef = 1.96, conf.int = FALSE, ...) {
stopifnot(any(class(fit) %in% c("cuminc", "survfitms")))

if (any(class(fit) == "cuminc")) {
pl <- ggcompetingrisks.cuminc(fit = fit, gnames=gnames,
gsep=gsep, multiple_panels=multiple_panels,
coef = coef, add_ci = add_ci)
coef = coef, conf.int = conf.int)
}
if (any(class(fit) == "survfitms")) {
pl <- ggcompetingrisks.survfitms(fit = fit)
Expand All @@ -67,7 +67,7 @@ ggcompetingrisks <- function(fit, gnames = NULL, gsep=" ",


ggcompetingrisks.cuminc <- function(fit, gnames = NULL, gsep=" ",
multiple_panels = TRUE, coef = 1.96, add_ci = FALSE) {
multiple_panels = TRUE, coef = 1.96, conf.int = FALSE) {
if (!is.null(fit$Tests))
fit <- fit[names(fit) != "Tests"]
fit2 <- lapply(fit, `[`, 1:3)
Expand All @@ -81,14 +81,14 @@ ggcompetingrisks.cuminc <- function(fit, gnames = NULL, gsep=" ",
df <- do.call(rbind, fit2_list)
df$event <- sapply(strsplit(df$name, split=gsep), `[`, 2)
df$group <- sapply(strsplit(df$name, split=gsep), `[`, 1)
df$std <- sqrt(df$var)
df$std <- std <- sqrt(df$var)
pl <- ggplot(df, aes(time, est, color=event))
if (multiple_panels) {
pl <- ggplot(df, aes(time, est, color=event)) + facet_wrap(~group)
} else {
pl <- ggplot(df, aes(time, est, color=event, linetype=group))
}
if (add_ci) {
if (conf.int) {
pl <- pl + geom_ribbon(aes(ymin = est - coef*std, ymax=est + coef*std, fill = event), alpha = 0.2, linetype=0)
}
pl +
Expand Down
2 changes: 1 addition & 1 deletion R/ggcoxadjustedcurves.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ NULL
#'@param individual.curves if TRUE then all individual predicted survival curves will be plotted
#'@param curve.size,curve.alpha size and alpha for individual survival curves
#'@param ylab y axis label.
#'@param ggtheme function, ggplot2 theme name. Default value is \link{theme_classic2}.
#'@param ggtheme function, ggplot2 theme name.
#' Allowed values include ggplot2 official themes: see \code{\link[ggplot2]{theme}}.
#'@inheritParams ggpubr::ggpar
#'@param ... further arguments passed to the function \code{\link[ggpubr]{ggpar}} for customizing the plot.
Expand Down
2 changes: 1 addition & 1 deletion R/ggcoxfunctional.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ NULL
#'@param title the title of the final \link{grob} (\code{top} in \link{arrangeGrob})
#'@param caption the caption of the final \link{grob} (\code{bottom} in \link{arrangeGrob})
#'@param point.col,point.size,point.shape,point.alpha color, size, shape and visibility to be used for points.
#'@param ggtheme function, ggplot2 theme name. Default value is \link{theme_classic2}.
#'@param ggtheme function, ggplot2 theme name.
#' Allowed values include ggplot2 official themes: see \code{\link[ggplot2]{theme}}.
#'@param ... further arguments passed to the function \code{\link[ggpubr]{ggpar}} for customizing the plot.
#'@return Returns an object of class \code{ggcoxfunctional} which is a list of ggplots.
Expand Down
2 changes: 1 addition & 1 deletion R/ggcoxzph.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' are produced in turn for each variable of a model.
#'@param point.col,point.size,point.shape,point.alpha color, size, shape and visibility to be used for points.
#'@param caption the caption of the final \link{grob} (\code{bottom} in \link{arrangeGrob})
#'@param ggtheme function, ggplot2 theme name. Default value is \link{theme_classic2}.
#'@param ggtheme function, ggplot2 theme name.
#' Allowed values include ggplot2 official themes: see \code{\link[ggplot2]{theme}}.
#'@param ... further arguments passed to either the print() function or to the \code{\link[ggpubr]{ggpar}} function for customizing the plot (see Details section).
#'@details \strong{Customizing the plots}: The plot can be easily
Expand Down
2 changes: 1 addition & 1 deletion R/ggsurvevents.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param data a dataset for predictions. If not supplied then data will be extracted from `fit` object.
#' @param type one of \code{c("cumulative", "radius", "fraction")}. \code{"cumulative"} stands for cumulative number of events, \code{"radius"} stands for number of events within a given radius,
#' @param normalized if \code{TRUE} relative number of events is presented,
#' @param ggtheme function, ggplot2 theme name. Default value is theme_classic2. Allowed values include ggplot2 official themes: see theme.
#' @param ggtheme function, ggplot2 theme name. Allowed values include ggplot2 official themes: see theme.
#' @param censored.on.top is TRUE then censored events are on the top
#' @param palette the color palette to be used for coloring of significant variables.
#' @param ... other graphical parameters to be passed to the function \link[ggpubr]{ggpar}.
Expand Down
1 change: 1 addition & 0 deletions R/ggsurvtheme.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ theme_cleantable <- function(base_size = 12, base_family = "", ...)
axis.line.y = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank()
)
Expand Down
19 changes: 19 additions & 0 deletions R/pairwise_survdiff.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pairwise_survdiff <- function(formula, data, p.adjust.method = "BH", na.action,
METHOD <- if (rho == 0) "Log-Rank test"
else if(rho==1) "Peto & Peto test"


# Removing missing value
# ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.is.na <- data[, group_var, drop = FALSE] %>%
Expand All @@ -72,6 +73,7 @@ pairwise_survdiff <- function(formula, data, p.adjust.method = "BH", na.action,
formula <- .build_formula(surv_obj, "..group..")
}
if(!is.factor(group)) group <- as.factor(group)
group <- droplevels(group)

compare.levels <- function(i, j) {
.subset = group %in% (levels(group))[c(i,j)]
Expand All @@ -87,3 +89,20 @@ pairwise_survdiff <- function(formula, data, p.adjust.method = "BH", na.action,
class(res) <- "pairwise.htest"
res
}


# Collapse one or two vectors
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.collapse <- function(x, y = NULL, sep = "."){
if(missing(y))
paste(x, collapse = sep)
else if(is.null(x) & is.null(y))
return(NULL)
else if(is.null(x))
return (as.character(y))
else if(is.null(y))
return(as.character(x))
else
paste0(x, sep, y)
}

6 changes: 3 additions & 3 deletions R/surv_cutpoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ print.surv_cutpoint <- function(x, ...){


#' @param ggtheme function, ggplot2 theme name. Default value is
#' \link{theme_classic2}. Allowed values include ggplot2 official themes. see
#' \link{theme_classic}. Allowed values include ggplot2 official themes. see
#' ?ggplot2::ggtheme.
#' @param bins Number of bins for histogram. Defaults to 30.
#' @method plot surv_cutpoint
#' @rdname surv_cutpoint
#' @export
plot.surv_cutpoint <- function(x, variables = NULL, ggtheme = theme_classic2(), bins = 30, ...)
plot.surv_cutpoint <- function(x, variables = NULL, ggtheme = theme_classic(), bins = 30, ...)
{

if(!inherits(x, "surv_cutpoint"))
Expand Down Expand Up @@ -271,7 +271,7 @@ print.plot_surv_cutpoint <- function(x, ..., newpage = TRUE){
# Helper function
# %%%%%%%%%%%%%%%%%%%%%

.ggpar <- function(p, ggtheme = theme_classic2(),...){
.ggpar <- function(p, ggtheme = theme_classic(),...){
argmt <- list(...)
p <- ggpubr::ggpar(p, ggtheme = ggtheme,...)
if(is.null(argmt$font.x)) p <- p + theme(axis.text.x = element_text(face = "plain"))
Expand Down
31 changes: 0 additions & 31 deletions R/theme_classic2.R

This file was deleted.

Loading

0 comments on commit dabe9cc

Please sign in to comment.