https://jinseob2kim.github.io/jskm/
R package for Kaplan-Meier Plot: Modified ggkm
https://jinseob2kim.github.io/jskm/
kaplan-meier-plot r weighted-kaplan-meier-plot
Last synced: 16 days ago
JSON representation
R package for Kaplan-Meier Plot: Modified ggkm
- Host: GitHub
- URL: https://jinseob2kim.github.io/jskm/
- Owner: jinseob2kim
- License: apache-2.0
- Created: 2018-07-05T14:38:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-10-24T09:12:59.000Z (about 2 months ago)
- Last Synced: 2025-10-24T10:28:55.601Z (about 2 months ago)
- Topics: kaplan-meier-plot, r, weighted-kaplan-meier-plot
- Language: R
- Homepage: https://jinseob2kim.github.io/jskm/
- Size: 16.1 MB
- Stars: 29
- Watchers: 1
- Forks: 21
- Open Issues: 3
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ggplot2 - jskm - Meier Plot (Data and models)
README
---
title: "jskm"
output: github_document
editor_options:
chunk_output_type: console
---
Kaplan-Meier Plot with 'ggplot2': 'survfit' and 'svykm' objects from 'survival' and 'survey' packages.
[](https://ci.appveyor.com/project/jinseob2kim/jskm)
[](https://github.com/jinseob2kim/jskm/actions)
[](https://cran.r-project.org/package=jskm)
[](https://CRAN.R-project.org/package=jskm)
[](https://app.codecov.io/github/jinseob2kim/jskm)
[](https://github.com/jinseob2kim/jskm/issues)
[](https://github.com/jinseob2kim/jskm/stargazers)
[](https://github.com/jinseob2kim/jskm/blob/master/LICENSE)
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = F, warning = F, fig.path = "man/figures/README-")
library(jskm)
```
## Install
```r
install.packages("jskm")
## From github: latest version
install.packages("remotes")
remotes::install_github("jinseob2kim/jskm")
library(jskm)
```
## Example
### Survival probability
```{r}
# 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, med = 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), showpercent = T
)
```
### Cumulative hazard: 1- Survival probability
```{r}
jskm(fit, ci = T, cumhaz = T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, pval.size = 6, pval.coord = c(300, 0.7))
```
### Landmark analysis
```{r}
jskm(fit, mark = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 500)
jskm(fit, mark = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 500, showpercent = T)
```
### Competing risk analysis
`status2` variable: 0 - censoring, 1 - event, 2 - competing risk
```{r}
## Make competing risk variable, Not real
colon$status2 <- colon$status
colon$status2[1:400] <- 2
colon$status2 <- factor(colon$status2)
fit2 <- survfit(Surv(time, status2) ~ rx, data = colon)
jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1")
jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1", showpercent = T, cut.landmark = 500)
```
### Theme
#### JAMA
```{r}
jskm(fit, theme = "jama", cumhaz = T, table = T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, pval.size = 6, pval.coord = c(300, 0.7))
```
#### NEJM
```{r}
jskm(fit, theme = "nejm", nejm.infigure.ratiow = 0.7, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0, 0.7), cumhaz = T, table = T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, pval.size = 6, pval.coord = c(300, 0.7))
```
### Weighted Kaplan-Meier plot - `svykm.object` in **survey** package
```{r}
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 incidence (%)", surv.scale = "percent", pval = T, design = dpbc, pval.coord = c(300, 0.7), showpercent = T)
```
If you want to get **confidence interval**, you should apply `se = T` option to `svykm` object.
```{r}
s3 <- svykm(Surv(time, status > 0) ~ sex, design = dpbc, se = T)
svyjskm(s3)
svyjskm(s3, ci = F)
svyjskm(s3, ci = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 1000, showpercent = T)
```
### Theme
#### JAMA
```{r}
svyjskm(s2, theme = "jama", pval = T, table = T, design = dpbc)
```
#### NEJM
```{r}
svyjskm(s2, theme = "nejm", nejm.infigure.ratiow = 0.45, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0.2, 1), pval = T, table = T, design = dpbc)
```