ggkmcif2 {reportRmd}R Documentation

Plot KM and CIF curves with ggplot

Description

This function will plot a KM or CIF curve with option to add the number at risk. You can specify if you want confidence bands, the hazard ratio, and pvalues, as well as the units of time used.

Usage

ggkmcif2(
  response,
  cov = NULL,
  data,
  pval = TRUE,
  conf.curves = FALSE,
  table = TRUE,
  xlab = "Time",
  ylab = NULL,
  col = NULL,
  times = NULL,
  type = NULL,
  plot.event = 1,
  ...
)

Arguments

response

character vector with names of columns to use for response

cov

String specifying the column name of stratification variable

data

dataframe containing your data

pval

boolean to specify if you want p-values in the plot (Log Rank test for KM and Gray's test for CIF)

conf.curves

boolean to specify if you want confidence interval bands

table

Logical value. If TRUE, includes the number at risk table

xlab

String corresponding to xlabel. By default is "Time"

ylab

String corresponding to ylabel. When NULL uses "Survival

col

vector of colours

times

Numeric vector of times for the x-axis probability" for KM cuves, and "Probability of an event" for CIF

type

string indicating he type of univariate model to fit. The function will try and guess what type you want based on your response. If you want to override this you can manually specify the type. Options include "KM", and ,"CIF"

plot.event

Which event(s) to plot (1,2, or c(1,2))

...

additional plotting arguments see ggkmcif2Parameters

Details

Note that for proper pdf output of special characters the following code needs to be included in the first chunk of the rmd knitr::opts_chunk$set(dev="cairo_pdf")

Value

ggplot object; if table = F then only curves are output; if table = T then curves and risk table are output together

Examples

# Simple plot without confidence intervals
data("pembrolizumab")
ggkmcif2(response = c('os_time','os_status'),
cov='cohort',
data=pembrolizumab)

# Plot with median survival time
ggkmcif2(response = c('os_time','os_status'),
cov='sex',
data=pembrolizumab,
median.text = TRUE,median.lines=TRUE,conf.curves=TRUE)

# Plot with specified survival times and log-log CI
ggkmcif2(response = c('os_time','os_status'),
cov='sex',
data=pembrolizumab,
median.text = FALSE,set.time.text = 'mo OS',
set.time = c(12,24),conf.type = 'log-log',conf.curves=TRUE)

# KM plot with 95% CI and censor marks
ggkmcif2(c('os_time','os_status'),'sex',data = pembrolizumab, type = 'KM',
HR=TRUE, HR_pval = TRUE, conf.curves = TRUE,conf.type='log-log',
set.time.CI = TRUE, censor.marks=TRUE)

[Package reportRmd version 0.1.0 Index]