-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
127 lines (95 loc) · 4.81 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.align = "center",
out.width = "90%",
dpi = 300,
warning = FALSE,
message = FALSE,
dev = "ragg_png"
)
```
# KMunicate-Style Kaplan–Meier Plots
<!-- badges: start -->
[![Codecov test coverage](https://codecov.io/gh/ellessenne/KMunicate-package/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ellessenne/KMunicate-package?branch=master)
[![CRAN status](https://www.r-pkg.org/badges/version/KMunicate)](https://CRAN.R-project.org/package=KMunicate)
[![CRAN_Logs_Badge](http://cranlogs.r-pkg.org/badges/KMunicate)](https://cran.r-project.org/package=KMunicate)
[![CRAN_Logs_Badge_Total](http://cranlogs.r-pkg.org/badges/grand-total/KMunicate)](https://cran.r-project.org/package=KMunicate)
[![R-CMD-check](https://github.com/ellessenne/KMunicate-package/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ellessenne/KMunicate-package/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
The goal of {KMunicate} is to produce Kaplan–Meier plots in the style recommended following the [KMunicate study](http://dx.doi.org/10.1136/bmjopen-2019-030215) (TP Morris *et al*. Proposals on Kaplan–Meier plots in medical research and a survey of stakeholder views: KMunicate. *BMJ Open*, 2019, 9:e030215).
## Installation
You can install {KMunicate} from [CRAN](https://CRAN.R-project.org/package=KMunicate) by typing the following in your R console:
``` r
install.packages("KMunicate")
```
Alternatively, you can install the dev version of {KMunicate} from [GitHub](https://github.com/ellessenne/KMunicate-package/) with:
``` r
# install.packages("devtools")
devtools::install_github("ellessenne/KMunicate-package")
```
## Example
```{r packages}
library(survival)
library(KMunicate)
```
The {KMunicate} package comes with a couple of bundled dataset, `cancer` and `brcancer`.
The main function is named `KMunicate`:
```{r brcancer, fig.height = 7, fig.width = 7 / sqrt(2)}
KM <- survfit(Surv(rectime, censrec) ~ hormon, data = brcancer)
time_scale <- seq(0, max(brcancer$rectime), by = 365)
KMunicate(fit = KM, time_scale = time_scale)
```
```{r cancer, fig.height = 7, fig.width = 7 / sqrt(2)}
KM <- survfit(Surv(studytime, died) ~ drug, data = cancer2)
time_scale <- seq(0, max(cancer2$studytime), by = 7)
KMunicate(fit = KM, time_scale = time_scale)
```
You also might wonder, does this work with a single arm?
Yes, yes it does:
```{r cancer-single, fig.height = 6, fig.width = 6}
KM <- survfit(Surv(studytime, died) ~ 1, data = cancer2)
time_scale <- seq(0, max(cancer2$studytime), by = 7)
KMunicate(fit = KM, time_scale = time_scale)
```
Finally, you can also plot 1 - survival by using the argument `.reverse = TRUE`:
```{r brcancer-reverse, fig.height = 7, fig.width = 7 / sqrt(2)}
KM <- survfit(Surv(rectime, censrec) ~ hormon, data = brcancer)
time_scale <- seq(0, max(brcancer$rectime), by = 365)
KMunicate(fit = KM, time_scale = time_scale, .reverse = TRUE)
```
## Customise Risk Table
By default, `KMunicate()` will build a risk table conform to the KMunicate style, e.g., with cumulative number of events and censored (the column-wise sum is equal to the total number of individuals at risk per arm):
```{r brcancer-KMunicate, fig.height = 7, fig.width = 7 / sqrt(2)}
KM <- survfit(Surv(rectime, censrec) ~ hormon, data = brcancer)
time_scale <- seq(0, max(brcancer$rectime), by = 365)
KMunicate(fit = KM, time_scale = time_scale)
```
Alternatively, it is possible to customise the risk table via the `.risk_table` argument.
For instance, if one wants to have interval-wise number of events and censored, just pass the `survfit` value to the `.risk_table` argument:
```{r brcancer-survfit, fig.height = 7, fig.width = 7 / sqrt(2)}
KMunicate(fit = KM, time_scale = time_scale, .risk_table = "survfit")
```
This is the default output of the `summary.survfit()` function.
Finally, it is also possible to fully omit the risk table by setting `.risk_table = NULL`:
```{r brcancer-NULL, fig.height = 6 / sqrt(2), fig.width = 6}
KMunicate(fit = KM, time_scale = time_scale, .risk_table = NULL)
```
## Custom Fonts
Assuming you have set up your computer to use custom fonts with `ggplot2`, customising your KMunicate-style plot is trivial.
All you have to do is pass the font name as the `.ff` argument:
```{r cancer-single-ff, fig.height = 6, fig.width = 6}
KM <- survfit(Surv(studytime, died) ~ 1, data = cancer2)
time_scale <- seq(0, max(cancer2$studytime), by = 7)
KMunicate(fit = KM, time_scale = time_scale, .ff = "Times New Roman")
```
## Further Customisation
Several options to further customise each plot are provided, see e.g. the introductory vignette for more details.