Skip to contents

Plot survival curves using Highcharts

Usage

# S3 method for class 'survfit'
hchart(
  object,
  ...,
  fun = NULL,
  markTimes = TRUE,
  symbol = "plus",
  markerColor = NULL,
  ranges = FALSE,
  rangesOpacity = 0.3
)

Arguments

object

A survfit object as returned from the survfit function

...

Extra parameters to pass to hc_add_series function

fun

A function or the name of a survival curve transformation. "log" shows survival probabilities on a logarithmic y-axis. "cloglog" plots log(-log(S)) against positive time on a logarithmic x-axis. Both modes leave gaps where a curve or its confidence band falls outside the scale's domain. "event" plots 1 - S and "cumhaz" plots -log(S).

markTimes

Label curves marked at each censoring time? TRUE by default

symbol

Symbol to use as marker (plus sign by default)

markerColor

Color of the censoring markers. By default (NULL), each marker uses the color of its survival curve.

ranges

Plot interval ranges? FALSE by default

rangesOpacity

Opacity of the interval ranges (0.3 by default)

Value

Highcharts object to plot survival curves

Examples

library(survival)

# Plot Kaplan-Meier curves
leukemia.surv <- survfit(Surv(time, status) ~ x, data = aml)
hchart(leukemia.surv)
# Plot the cumulative hazard function lsurv2 <- survfit(Surv(time, status) ~ x, aml, type = "fleming") hchart(lsurv2, fun = "cumhaz")
# Plot the fit of a Cox proportional hazards regression model fit <- coxph(Surv(futime, fustat) ~ age, data = ovarian) profiles <- data.frame(age = c(50, 70), row.names = c("Age 50", "Age 70")) ovarian.surv <- survfit(fit, newdata = profiles) hchart(ovarian.surv, ranges = TRUE)