plot_surv_area {contsurvplot} | R Documentation |

Using a previously fit time-to-event model, this function plots a survival curve or CIF area plot. Instead of plotting value-specific curves, the probability of interest is represented as an area as a function of time, where the color changes according to the continuous variable.

```
plot_surv_area(time, status, variable, group=NULL,
data, model, cif=FALSE,
na.action=options()$na.action,
horizon=NULL, fixed_t=NULL, max_t=Inf,
start_color="blue", end_color="red", alpha=1,
discrete=FALSE, bins=ifelse(discrete, 10, 40),
sep_lines=FALSE, sep_color="black",
sep_size=0.1, sep_linetype="solid",
sep_alpha=alpha, xlab="Time",
ylab="Survival Probability", title=NULL,
subtitle=NULL, legend.title=variable,
legend.position="right",
gg_theme=ggplot2::theme_bw(),
facet_args=list(), label_digits=NULL,
transition_size=0.01, kaplan_meier=FALSE,
km_size=0.5, km_linetype="solid", km_alpha=1,
km_color="black", monotonic=TRUE, ...)
```

`time` |
A single character string specifying the time-to-event variable. Needs to be a valid column name of a numeric variable in |

`status` |
A single character string specifying the status variable, indicating if a person has experienced an event or not. Needs to be a valid column name of a numeric or logical variable in |

`variable` |
A single character string specifying the continuous variable of interest, for which the survival curves should be estimated. This variable has to be contained in the |

`group` |
An optional single character string specifying a factor variable in |

`data` |
A |

`model` |
A model describing the time-to-event process (such as an |

`cif` |
Whether to plot the cumulative incidence (CIF) instead of the survival probability. If multiple failure types are present, the survival probability cannot be estimated in an unbiased way. This function will always return CIF estimates in that case. |

`na.action` |
How missing values should be handled. Can be one of: |

`horizon` |
A numeric vector containing a range of values of |

`fixed_t` |
A numeric vector containing points in time at which the survival probabilities should be calculated or |

`max_t` |
A number indicating the latest survival time which is to be plotted. |

`start_color` |
The color used for the lowest value in |

`end_color` |
The color used for the highest value in |

`alpha` |
The transparency level of the main plot. |

`discrete` |
Whether to plot the area as a single continuously shaded area (default) or as multiple discrete blocks. The blocks correspond to ranges (such as 5-10). This only really changes the style of the legend and decreases the default value of |

`bins` |
The number of bins the survival area should be divided into. In a nutshell, this function simply estimates a lot of covariate specific curves and colors the area between them on a graded scale. If many bins are used, this gives the appearance of a single shaded area, changing continuously. By using only a few bins however, the specific covariate values might be easier to read off the plot. See also the |

`sep_lines` |
Whether to draw lines between the individual area segments or not. When |

`sep_color` |
The color of the separator lines. Ignored if |

`sep_size` |
The size of the separator lines. Ignored if |

`sep_linetype` |
The linetype of the separator lines. Ignored if |

`sep_alpha` |
The transparency level of the separator lines. Ignored if |

`xlab` |
A character string used as the x-axis label of the plot. |

`ylab` |
A character string used as the y-axis label of the plot. |

`title` |
A character string used as the title of the plot. |

`subtitle` |
A character string used as the subtitle of the plot. |

`legend.title` |
A character string used as the legend title of the plot. |

`legend.position` |
Where to put the legend. See |

`gg_theme` |
A ggplot2 theme which is applied to the plot. |

`facet_args` |
A named list of arguments that are passed to the |

`label_digits` |
A single number specifying to how many digits the labels of the plot should be rounded or |

`transition_size` |
A single number > 0 specifying the |

`kaplan_meier` |
Whether to add a standard Kaplan-Meier estimator to the plot or not. If |

`km_size` |
The size of the Kaplan-Meier line. Ignored if |

`km_linetype` |
The linetype of the Kaplan-Meier line. Ignored if |

`km_alpha` |
The transparency level of the Kaplan-Meier line. Ignored if |

`km_color` |
The color of the Kaplan-Meier line. Ignored if |

`monotonic` |
A single logical value specifying whether the relationship between the |

`...` |
Further arguments passed to |

This function is very similar to a contour plot (see `plot_surv_contour`

), but with the probability of interest on the y-axis and the color representing the values of the continuous variable of interest. The main advantage of this type of plot is, that it has the same structure as a usual Kaplan-Meier plot. The only difference is that instead of single curves stratified by some variable, the curves are plotted as an area instead.

This is achieved by estimating value-specific curves over the whole range of the continuous covariate using direct standardization and a previously fitted time-to-event model (see `curve_cont`

). The area between those curves is then simply filled in (using the `geom_stepribbon`

function from the pammtools package). By using a big number of individual curves, the appearance of a continuously shaded area is created. This is done by default when using the argument `discrete=FALSE`

. By using `discrete=TRUE`

, only a small number of value-specific curves are estimated, resulting in only a few discrete bins. When using only a few bins, the output is therefore even closer to a contour plot.

The major downside of this plotting method is that it has problems handling non-monotone effects. Curved relationships between the variable and the survival time result in the areas being plotted on top of each other in a standard survival area plot. By using `monotonic=FALSE`

, the user may still use this function for nonlinear effects. This strategy is not optimal when the relationship is very complex, resulting in lots of facets in the plot. We recommend using either the `plot_surv_contour`

, `plot_surv_heatmap`

or `plot_surv_matrix`

functions in this case.

Returns a `ggplot2`

object.

When saving this graphic to `.png`

or `.jpg`

files while using `discrete=FALSE`

, they may sometimes contain some barely visible (but very annoying) lines. Those are the divisions between the areas the plot is made off. This only happens when saving this plot to non-vector graphics, which is why we recommend saving it to `.pdf`

or similar file types only. If other file types are necessary, one can set the `transition_size`

argument to higher values (such as 0.5 or 1) to remove this problem as well.

Robin Denz

Robin Denz, Nina Timmesfeld (2022). Visualizing the Causal Effect of a Continuous Variable on a Time-To-Event Outcome. arXiv:2208.04644v1

```
library(contsurvplot)
library(riskRegression)
library(survival)
library(ggplot2)
library(pammtools)
# using data from the survival package
data(nafld, package="survival")
# take a random sample to keep example fast
set.seed(42)
nafld1 <- nafld1[sample(nrow(nafld1), 100), ]
# fit cox-model with age
model <- coxph(Surv(futime, status) ~ age, data=nafld1, x=TRUE)
# plot effect of age on survival using defaults
plot_surv_area(time="futime",
status="status",
variable="age",
data=nafld1,
model=model)
# plot it only for 60 to 80 year old people
plot_surv_area(time="futime",
status="status",
variable="age",
data=nafld1,
model=model,
horizon=seq(60, 80, 0.5))
# plot it only for 60 to 60 year old people, using discrete bins
# and a black and white color scale
plot_surv_area(time="futime",
status="status",
variable="age",
data=nafld1,
model=model,
horizon=seq(60, 80, 5),
discrete=TRUE,
start_color="grey",
end_color="black")
```

[Package *contsurvplot* version 0.2.0 Index]