Kaplan-Meier Plot with 'ggplot2'

The function 'jskm()' creates publication quality Kaplan-Meier plot with at risk tables below. 'svyjskm()' provides plot for weighted Kaplan-Meier estimator.


Kaplan-Meier Plot with 'ggplot2': 'survfit' and 'svykm' objects from 'survival' and 'survey' packages.

Build Status AppVeyor build status CRAN_Status_Badge CRAN_Download_Badge codecov GitHub issues GitHub stars GitHub license

Install

install.packages("jskm")
install.packages("remotes")
remotes::install_github("jinseob2kim/jskm")
 
library(jskm)

Example

Survival probability

#Load dataset
library(survival)
data(colon)
fit <- survfit(Surv(time,status)~rx, data=colon)
 
#Plot the data
jskm(fit)

jskm(fit, table = T, pval = T, label.nrisk = "No. at risk", size.label.nrisk = 8, 
     xlabs = "Time(Day)", ylabs = "Survival", ystratalabs = c("Obs", "Lev", "Lev + 5FU"), ystrataname = "rx",
     marks = F, timeby = 365, xlims = c(0, 3000), ylims = c(0.25, 1))

Cumulative hazard: 1- Survival probability

jskm(fit, ci = T, cumhaz = T,  mark = F, ylab = "Cumulative hazard (%)", surv.scale = "percent", pval =T, pval.size = 6, pval.coord = c(300, 0.7))

Weighted Kaplan-Meier plot - svykm.object in survey package

library(survey)
data(pbc, package="survival")
pbc$randomized <- with(pbc, !is.na(trt) & trt>0)
biasmodel <- glm(randomized~age*edema,data=pbc)
pbc$randprob <- fitted(biasmodel)
 
dpbc<-svydesign(id=~1, prob=~randprob, strata=~edema, data=subset(pbc,randomized))
 
s1 <-svykm(Surv(time,status>0) ~ 1, design = dpbc)
s2 <-svykm(Surv(time,status>0) ~ sex, design = dpbc)
 
svyjskm(s1)

svyjskm(s2, pval = T,  table = T, design = dpbc)

svyjskm(s2, cumhaz = T, ylab = "Cumulative (%)", surv.scale = "percent", pval = T, design = dpbc, pval.coord = c(300, 0.7)) 

If you want to get confidence interval, you should apply se = T option to svykm object.

s3 <- svykm(Surv(time,status>0) ~ sex, design=dpbc, se = T)
svyjskm(s3)

svyjskm(s3, ci = F)

News

jskm 0.3.1

Update

  • The p-value is expressed as the value rounded to the 3rd decimal place.

  • Add pval.testname option, p-value is expressed with (Log-rank) text if pval.testname == T.

jskm 0.3.0

New feature

  • Add Number at risk table option to svyjskm. The number at risk is no-weighted values (same to jskm).

Bug fixes

  • Appropriate default pval.coord in svyjskm.

jskm 0.2.8

Bug fixes

  • Add namespace survival::frailty, survival::cluster.

jskm 0.2.7

Bug fixes

  • Fix some spell for cran release.

Update

  • Update travis-ci.

  • Add appveyor CI to test window environment.

jskm 0.2.6

Bug fixes

  • Change ||, && to |, & for Debian environment.

  • Set some variable's initial values to NULL for cran release.

jskm 0.2.5

Bug fixes

  • Remove gray rectangle above the Number at risk table.

  • Change p-value position according ylims option.

Update

  • Add Numbers at risk label option to jskm: label.nrisk, size.label.nrisk.

  • Add percent scale option : surv.scale.

  • Add pvalue position & font size option : pval.size, pval.coord

jskm 0.2.4

Update

  • Add ci option to svyjskm.

  • Get p-value without design option in svyjskm

jskm 0.2.2

  • Apply testthat

jskm 0.2.1

  • Can run when reactive data

jskm 0.2.0

New function

  • svyjskm : Weighted Kaplan-Meier plot - svykm.object in survey package

jskm 0.1.0

  • frailty, cluster options and their p value

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("jskm")

0.3.6 by Jinseob Kim, 20 days ago


https://github.com/jinseob2kim/jskm


Report a bug at https://github.com/jinseob2kim/jstable/issues


Browse source code at https://github.com/cran/jskm


Authors: Jinseob Kim [aut, cre] , Zarathu [cph, fnd]


Documentation:   PDF Manual  


Apache License 2.0 license


Imports ggplot2, gridExtra, plyr, survival, survey, scales

Suggests testthat, knitr, rmarkdown


Imported by jsmodule.


See at CRAN