View source: R/ggkmrisktable.R
ggkmrisktable | R Documentation |
Produces a km plot with a facettable risk table in ggplot2
ggkmrisktable(
data = lung_long,
time = "time",
status = "DV",
endpoint = "Endpoint",
groupvar1 = "Endpoint",
groupvar2 = "expname",
groupvar3 = "none",
exposure_metrics = c("age", "ph.karno"),
exposure_metric_split = c("median", "tertile", "quartile", "none"),
exposure_metric_soc_value = -99,
exposure_metric_plac_value = 0,
color_fill = "exptile",
linetype = "exptile",
xlab = "Time of follow_up",
ylab = "Overall survival probability",
nrisk_table_plot = TRUE,
nrisk_table_variables = c("n.risk", "pct.risk", "n.event", "cum.n.event", "n.censor"),
nrisk_table_breaktimeby = NULL,
nrisk_table_textsize = 4,
nrisk_position_scaler = 0.2,
nrisk_position_dodge = 0.2,
nrisk_offset = 0,
nrisk_filterout0 = FALSE,
km_logrank_pvalue = FALSE,
km_logrank_pvalue_pos = c("left", "right"),
km_trans = c("identity", "event", "cumhaz", "cloglog"),
km_ticks = TRUE,
km_band = TRUE,
km_conf_int = 0.95,
km_conf_type = c("log", "plain", "log", "log-log", "logit", "none"),
km_conf_lower = c("usual", "peto", "modified"),
km_median = c("none", "median", "medianci", "table"),
km_median_table_pos = c("left", "right"),
km_median_table_order = c("default", "reverse"),
km_yaxis_position = c("left", "right"),
facet_formula = NULL,
facet_ncol = NULL,
facet_strip_position = c("top", "top", "top", "top"),
theme_certara = TRUE
)
data |
Data to use with multiple endpoints stacked into time, status, endpoint name |
time |
name of the column holding the time to event information default to |
status |
name of the column holding the event information default to |
endpoint |
name of the column holding the name/key of the endpoint default to |
groupvar1 |
name of the column to group by, default |
groupvar2 |
name of the column to group by in addition to groupvar1, default |
groupvar3 |
name of the column to group by in addition to groupvar1 and groupvar2, default "none" |
exposure_metrics |
name(s) of the column(s) to be stacked into |
exposure_metric_split |
one of "median", "tertile", "quartile", "none" |
exposure_metric_soc_value |
special exposure code for standard of care default -99 |
exposure_metric_plac_value |
special exposure code for placebo default 0 |
color_fill |
name of the column to be used for color/fill default to |
linetype |
name of the column to be used for linetype default to |
xlab |
text to be used as x axis label |
ylab |
text to be used as y axis label |
nrisk_table_plot |
TRUE |
nrisk_table_variables |
one or more from: "n.risk", "pct.risk", "n.event, "cum.n.event, "n.censor" |
nrisk_table_breaktimeby |
NULL |
nrisk_table_textsize |
4 |
nrisk_position_scaler |
0.2 |
nrisk_position_dodge |
0.2, negative values will reverse the order |
nrisk_offset |
0 |
nrisk_filterout0 |
FALSE |
km_logrank_pvalue |
FALSE |
km_logrank_pvalue_pos |
"left" or "right" |
km_trans |
one of "identity","event","cumhaz","cloglog" |
km_ticks |
TRUE |
km_band |
TRUE |
km_conf_int |
0.95 |
km_conf_type |
default one of "log", "plain", "log-log", "logit", "none" |
km_conf_lower |
one of "usual", "peto", "modified" |
km_median |
add median survival information one of "none", "median", "medianci", "table" |
km_median_table_pos |
when table is chosen where to put it "left" or "right |
km_median_table_order |
when table is chosen the order of the entries "default" or "reverse" |
km_yaxis_position |
where to put y axis on "left" or "right |
facet_formula |
facet formula to be used otherwise ~ groupvar1 + groupvar2 + groupvar3 |
facet_ncol |
NULL if not specified the automatic waiver will be used |
facet_strip_position |
position in sequence for the variable used in faceting default to c("top","top","top","top") |
theme_certara |
apply certara colors and format for strips and default colour/fill |
library(tidyr)
# Example 1
lung_long <- survival::lung |>
dplyr::mutate(status = ifelse(status==1,0,1)) |>
tidyr::gather(Endpoint,DV,status) |>
dplyr::filter(!is.na(ph.karno))|>
dplyr::filter(!is.na(pat.karno))|>
dplyr::filter(!is.na(ph.ecog))
lung_long$ph.ecog <- ifelse(lung_long$ph.ecog>1,2,lung_long$ph.ecog)
lung_long$ph.ecog <- as.factor(lung_long$ph.ecog )
lung_long$ph.ecog <- as.factor(lung_long$ph.ecog )
lung_long$facetdum <- "(all)"
ggkmrisktable(data = lung_long, time= "time", status ="DV",
exposure_metrics =c("age","ph.karno"),
exposure_metric_split = "tertile",
color_fill = "exptile",
linetype = "expname",
groupvar1 = "Endpoint",
groupvar2 = "exptile",
xlab = "Time of follow_up",
ylab ="Overall survival probability",
nrisk_table_variables = c("n.risk","n.event"),
km_median = "medianci",
km_band = FALSE,
nrisk_table_breaktimeby = 200,
facet_ncol = 3)
#Example 2
ggkmrisktable(data = lung_long, time= "time", status ="DV",
exposure_metrics =c("age","ph.karno"),
exposure_metric_split = "quartile",
color_fill = "exptile",
linetype = "none",
groupvar1 = "Endpoint",
groupvar2 = "exptile",
xlab = "Time of follow_up",
ylab ="Overall survival probability",
nrisk_table_variables = c("cum.n.event","pct.risk","n.censor"),
km_median = "medianci",
km_band = TRUE,
km_trans = "event",
nrisk_table_breaktimeby = 200,
facet_ncol = 3,
facet_formula = ~expname)
## Not run:
#Example 3
ggkmrisktable(data = lung_long, time = "time", status = "DV",
exposure_metrics =c("ph.karno","pat.karno"),
exposure_metric_split = "median",
color_fill = "exptile",
linetype = "exptile",
groupvar1 = "Endpoint",
groupvar2 = "expname",
xlab = "Time of follow_up",
ylab ="Overall survival probability",
nrisk_table_variables = c("n.event"),
km_trans = "event",
km_median = "table",
km_median_table_pos = "right",
km_logrank_pvalue = TRUE,
km_band = TRUE,
nrisk_table_breaktimeby = 200,
facet_ncol = 3,
facet_formula = ~expname)
#Example 4
ggkmrisktable(data=lung_long,
exposure_metrics = c("ph.karno","age"),
exposure_metric_split = "median",
time = "time",
status ="DV",
color_fill = "ph.ecog",
linetype = "ph.ecog",
groupvar1 = "Endpoint",
groupvar2 = "expname",
groupvar3 = "exptile",
nrisk_filterout0 = FALSE,
nrisk_table_breaktimeby = 200,
km_logrank_pvalue = TRUE,
km_median = "table",
km_median_table_pos = "left",
facet_formula = ~expname+exptile)
#Example 5
ggkmrisktable(data=lung_long,
exposure_metrics = c("ph.karno","age"),
exposure_metric_split = "none",
color_fill = "facetdum",
linetype = "none",
nrisk_table_variables = c("n.risk", "pct.risk", "n.event", "cum.n.event", "n.censor"),
km_median = "table",
nrisk_position_scaler = 0.1
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.