Title: | Quickly Explore Your Data Using 'ggplot2' and 'table1' Summary Tables |
---|---|
Description: | Quickly and easily perform exploratory data analysis by uploading your data as a 'csv' file. Start generating insights using 'ggplot2' plots and 'table1' tables with descriptive stats, all using an easy-to-use point and click 'Shiny' interface. |
Authors: | Samer Mouksassi [aut, cre] , Dean Attali [aut], James Craig [aut] (implemented bookmarking and created pkgdown website), Benjamin Rich [aut] (provided summary stats tables table1 tab code), Michael Sachs [aut] (provided ggkm initial code) |
Maintainer: | Samer Mouksassi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.1.9000 |
Built: | 2024-11-15 08:34:38 UTC |
Source: | https://github.com/smouksassi/ggquickeda |
Add a Kaplan-Meier survival curve
geom_km( mapping = NULL, data = NULL, stat = "km", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = TRUE, ... )
geom_km( mapping = NULL, data = NULL, stat = "km", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
na.rm |
If |
... |
Other arguments passed on to
|
geom_km
understands the following aesthetics (required aesthetics
are in bold):
x
The survival/censoring times. This is automatically mapped by stat_km()
y
The survival probability estimates. This is automatically mapped by stat_km()
smallest level in sort order is assumed to be 0, with a warning.
alpha
color
linetype
size
The default stat for this geom is stat_km()
see
that documentation for more options to control the underlying statistical transformation.
library(ggplot2) set.seed(123) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex))) + geom_km()
library(ggplot2) set.seed(123) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex))) + geom_km()
Add confidence bands to a Kaplan-Meier survival curve
geom_kmband( mapping = NULL, data = NULL, stat = "kmband", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = TRUE, ... )
geom_kmband( mapping = NULL, data = NULL, stat = "kmband", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
na.rm |
If |
... |
Other arguments passed on to
|
geom_kmband
understands the following aesthetics (required aesthetics
are in bold):
x
The survival/censoring times. This is automatically mapped by stat_kmband()
y
The survival probability estimates. This is automatically mapped by stat_kmband()
smallest level in sort order is assumed to be 0, with a warning
alpha
color
linetype
linewidth
The default stat for this geom is stat_kmband()
. See
that documentation for more options to control the underlying statistical transformation.
library(ggplot2) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex), fill =factor(sex))) + geom_km() + geom_kmband()
library(ggplot2) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex), fill =factor(sex))) + geom_km() + geom_kmband()
Adds tickmarks at the times when there are censored observations but no events
geom_kmticks( mapping = NULL, data = NULL, stat = "kmticks", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = TRUE, ... )
geom_kmticks( mapping = NULL, data = NULL, stat = "kmticks", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
na.rm |
If |
... |
Other arguments passed on to
|
geom_kmticks
understands the following aesthetics (required aesthetics
are in bold):
x
The survival/censoring times. This is automatically mapped by stat_kmticks()
y
The survival probability estimates. This is automatically mapped by stat_kmticks()
smallest level in sort order is assumed to be 0, with a warning
alpha
color
linetype
size
The default stat for this geom is stat_kmticks see that documentation for more options to control the underlying statistical transformation.
library(ggplot2) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex), group = factor(sex))) + geom_km() + geom_kmticks(col="black")
library(ggplot2) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex), group = factor(sex))) + geom_km() + geom_kmticks(col="black")
Produces a logistic fit plot with a facettable exposures/quantiles/distributions in ggplot2
ggcontinuousexpdist( data = effICGI, response = "response", endpoint = "Endpoint", DOSE = "DOSE", color_fill = "DOSE", exposure_metrics = c("AUC", "CMAX"), exposure_metric_split = c("median", "tertile", "quartile", "none"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, exposure_distribution = c("distributions", "lineranges", "none"), dose_plac_value = "Placebo", xlab = "Exposure Values", ylab = "Response", mean_obs_byexptile = TRUE, mean_text_size = 5, mean_obs_bydose = TRUE, mean_obs_bydose_plac = FALSE, N_text_size = 5, binlimits_text_size = 5, binlimits_ypos = -Inf, binlimits_color = "gray70", dist_position_scaler = 0.2, dist_offset = 0, dist_scale = 0.9, lineranges_ypos = -1, lineranges_dodge = 1, lineranges_doselabel = FALSE, proj_bydose = TRUE, yproj = TRUE, yproj_xpos = 0, yproj_dodge = 0.2, yaxis_position = c("left", "right"), facet_formula = NULL, theme_certara = TRUE, return_list = FALSE )
ggcontinuousexpdist( data = effICGI, response = "response", endpoint = "Endpoint", DOSE = "DOSE", color_fill = "DOSE", exposure_metrics = c("AUC", "CMAX"), exposure_metric_split = c("median", "tertile", "quartile", "none"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, exposure_distribution = c("distributions", "lineranges", "none"), dose_plac_value = "Placebo", xlab = "Exposure Values", ylab = "Response", mean_obs_byexptile = TRUE, mean_text_size = 5, mean_obs_bydose = TRUE, mean_obs_bydose_plac = FALSE, N_text_size = 5, binlimits_text_size = 5, binlimits_ypos = -Inf, binlimits_color = "gray70", dist_position_scaler = 0.2, dist_offset = 0, dist_scale = 0.9, lineranges_ypos = -1, lineranges_dodge = 1, lineranges_doselabel = FALSE, proj_bydose = TRUE, yproj = TRUE, yproj_xpos = 0, yproj_dodge = 0.2, yaxis_position = c("left", "right"), facet_formula = NULL, theme_certara = TRUE, return_list = FALSE )
data |
Data to use with multiple endpoints stacked into response (values), Endpoint(endpoint name) |
response |
name of the column holding the response values |
endpoint |
name of the column holding the name/key of the endpoint default to |
DOSE |
name of the column holding the DOSE values default to |
color_fill |
name of the column to be used for color/fill default to DOSE column |
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 |
exposure_distribution |
one of distributions, lineranges or none |
dose_plac_value |
string identifying placebo in DOSE column |
xlab |
text to be used as x axis label |
ylab |
text to be used as y axis label |
mean_obs_byexptile |
observed probability by exptile |
mean_text_size |
mean text size default to 5 |
mean_obs_bydose |
observed mean by dose |
mean_obs_bydose_plac |
observed probability by placebo dose |
N_text_size |
N by exposure bin text size default to 5 |
binlimits_text_size |
5 binlimits text size |
binlimits_ypos |
binlimits y position default to 0 |
binlimits_color |
binlimits text color default to "gray70" |
dist_position_scaler |
space occupied by the distribution default to 0.2 |
dist_offset |
offset where the distribution position starts default to 0 |
dist_scale |
scaling parameter for ggridges default to 0.9 |
lineranges_ypos |
where to put the lineranges -1 |
lineranges_dodge |
lineranges vertical dodge value 1 |
lineranges_doselabel |
|
proj_bydose |
project the probabilities on logistic curve |
yproj |
project the probabilities on y axis |
yproj_xpos |
y projection x position 0 |
yproj_dodge |
y projection dodge value 0.2 |
yaxis_position |
where to put y axis "left" or "right" |
facet_formula |
facet formula to be use otherwise |
theme_certara |
apply certara colors and format for strips and default colour/fill |
return_list |
What to return if True a list of the datasets and plot is returned instead of only the plot |
# Example 1 library(ggplot2) library(patchwork) effICGI <- logistic_data |> dplyr::filter(!is.na(ICGI7))|> dplyr::filter(!is.na(AUC)) effICGI$DOSE <- factor(effICGI$DOSE, levels=c("0", "600", "1200","1800","2400"), labels=c("Placebo", "600 mg", "1200 mg","1800 mg","2400 mg")) effICGI$STUDY <- factor(effICGI$STUDY) effICGI <- tidyr::gather(effICGI,Endpoint,response,ICGI7,BRLS) a <- ggcontinuousexpdist(data = effICGI |> dplyr::filter(Endpoint =="ICGI7"), response = "response", endpoint = "Endpoint", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 1, dist_offset = -1 , yproj_xpos = -20 , yproj_dodge = 20 , exposure_distribution ="distributions") b <- ggcontinuousexpdist(data = effICGI |> dplyr::filter(Endpoint =="BRLS"), response = "response", endpoint = "Endpoint", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 4.2, dist_offset = 5 , yproj_xpos = -20 , yproj_dodge = 20 , exposure_distribution ="distributions", return_list = FALSE) (a / b) + plot_layout(guides = "collect") & theme(legend.position = "top") #Example 2 effICGI$SEX <- as.factor(effICGI$SEX) ggcontinuousexpdist(data = effICGI |> dplyr::filter(Endpoint =="ICGI7"), response = "response", endpoint = "Endpoint", color_fill = "SEX", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 1, dist_offset = -1 , yproj_xpos = -20 , yproj_dodge = 20 , exposure_distribution ="lineranges") ## Not run: #Example 5 ## End(Not run)
# Example 1 library(ggplot2) library(patchwork) effICGI <- logistic_data |> dplyr::filter(!is.na(ICGI7))|> dplyr::filter(!is.na(AUC)) effICGI$DOSE <- factor(effICGI$DOSE, levels=c("0", "600", "1200","1800","2400"), labels=c("Placebo", "600 mg", "1200 mg","1800 mg","2400 mg")) effICGI$STUDY <- factor(effICGI$STUDY) effICGI <- tidyr::gather(effICGI,Endpoint,response,ICGI7,BRLS) a <- ggcontinuousexpdist(data = effICGI |> dplyr::filter(Endpoint =="ICGI7"), response = "response", endpoint = "Endpoint", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 1, dist_offset = -1 , yproj_xpos = -20 , yproj_dodge = 20 , exposure_distribution ="distributions") b <- ggcontinuousexpdist(data = effICGI |> dplyr::filter(Endpoint =="BRLS"), response = "response", endpoint = "Endpoint", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 4.2, dist_offset = 5 , yproj_xpos = -20 , yproj_dodge = 20 , exposure_distribution ="distributions", return_list = FALSE) (a / b) + plot_layout(guides = "collect") & theme(legend.position = "top") #Example 2 effICGI$SEX <- as.factor(effICGI$SEX) ggcontinuousexpdist(data = effICGI |> dplyr::filter(Endpoint =="ICGI7"), response = "response", endpoint = "Endpoint", color_fill = "SEX", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 1, dist_offset = -1 , yproj_xpos = -20 , yproj_dodge = 20 , exposure_distribution ="lineranges") ## Not run: #Example 5 ## End(Not run)
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, show_exptile_values = FALSE, show_exptile_values_pos = c("left", "right"), show_exptile_values_textsize = 5, show_exptile_values_order = c("default", "reverse"), 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_logrank_pvalue_textsize = 5, km_logrank_pvalue_cutoff = 0.001, km_logrank_pvalue_digits = 3, 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, return_list = FALSE )
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, show_exptile_values = FALSE, show_exptile_values_pos = c("left", "right"), show_exptile_values_textsize = 5, show_exptile_values_order = c("default", "reverse"), 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_logrank_pvalue_textsize = 5, km_logrank_pvalue_cutoff = 0.001, km_logrank_pvalue_digits = 3, 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, return_list = FALSE )
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 |
show_exptile_values |
FALSE |
show_exptile_values_pos |
"left" or "right" |
show_exptile_values_textsize |
default to 5 |
show_exptile_values_order |
the order of the entries "default" or "reverse" |
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_logrank_pvalue_textsize |
pvalue text size default to 5 |
km_logrank_pvalue_cutoff |
pvalue below which to print as p < cutoff |
km_logrank_pvalue_digits |
pvalue ndigits for round function |
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 |
return_list |
What to return if True a list of the datasets and plot is returned instead of only the plot |
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", show_exptile_values = TRUE, show_exptile_values_pos = "right", 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_logrank_pvalue_cutoff = 0.0001, km_logrank_pvalue_digits = 3, 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 = "none", 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)
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", show_exptile_values = TRUE, show_exptile_values_pos = "right", 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_logrank_pvalue_cutoff = 0.0001, km_logrank_pvalue_digits = 3, 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 = "none", 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)
Produces a logistic fit plot with a facettable exposures/quantiles/distributions in ggplot2
gglogisticexpdist( data = effICGI, response = "response", endpoint = "Endpoint", DOSE = "DOSE", color_fill = "DOSE", logistic_by_color_fill = FALSE, exposure_metrics = c("AUC", "CMAX"), exposure_metric_split = c("median", "tertile", "quartile", "none"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, exposure_distribution = c("distributions", "lineranges", "none"), exposure_distribution_percent = TRUE, exposure_distribution_percent_text_size = 5, dose_plac_value = "Placebo", xlab = "Exposure Values", ylab = "Probability of Response", points_alpha = 0.2, points_show = TRUE, prob_obs_byexptile = TRUE, prob_obs_byexptile_group = "none", prob_text_size = 5, prob_obs_bydose = TRUE, prob_obs_bydose_plac = FALSE, Nresp_Ntot = TRUE, Nresp_Ntot_ypos = c("with percentages", "top"), Nresp_Ntot_sep = "/", binlimits_show = TRUE, binlimits_text_size = 5, binlimits_ypos = 0, binlimits_color = "gray70", dist_position_scaler = 0.2, dist_offset = 0, dist_scale = 0.9, lineranges_ypos = 0.2, lineranges_dodge = 0.15, lineranges_doselabel = FALSE, proj_bydose = TRUE, yproj = TRUE, yproj_xpos = 0, yproj_dodge = 0.2, yaxis_position = c("left", "right"), facet_formula = NULL, theme_certara = TRUE, return_list = FALSE )
gglogisticexpdist( data = effICGI, response = "response", endpoint = "Endpoint", DOSE = "DOSE", color_fill = "DOSE", logistic_by_color_fill = FALSE, exposure_metrics = c("AUC", "CMAX"), exposure_metric_split = c("median", "tertile", "quartile", "none"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, exposure_distribution = c("distributions", "lineranges", "none"), exposure_distribution_percent = TRUE, exposure_distribution_percent_text_size = 5, dose_plac_value = "Placebo", xlab = "Exposure Values", ylab = "Probability of Response", points_alpha = 0.2, points_show = TRUE, prob_obs_byexptile = TRUE, prob_obs_byexptile_group = "none", prob_text_size = 5, prob_obs_bydose = TRUE, prob_obs_bydose_plac = FALSE, Nresp_Ntot = TRUE, Nresp_Ntot_ypos = c("with percentages", "top"), Nresp_Ntot_sep = "/", binlimits_show = TRUE, binlimits_text_size = 5, binlimits_ypos = 0, binlimits_color = "gray70", dist_position_scaler = 0.2, dist_offset = 0, dist_scale = 0.9, lineranges_ypos = 0.2, lineranges_dodge = 0.15, lineranges_doselabel = FALSE, proj_bydose = TRUE, yproj = TRUE, yproj_xpos = 0, yproj_dodge = 0.2, yaxis_position = c("left", "right"), facet_formula = NULL, theme_certara = TRUE, return_list = FALSE )
data |
Data to use with multiple endpoints stacked into response (values 0/1), Endpoint(endpoint name) |
response |
name of the column holding the response values 0/1 |
endpoint |
name of the column holding the name/key of the endpoint default to |
DOSE |
name of the column holding the DOSE values default to |
color_fill |
name of the column to be used for color/fill default to DOSE column |
logistic_by_color_fill |
logistic fit split by color ? default |
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 |
exposure_distribution |
one of distributions, lineranges or none |
exposure_distribution_percent |
show percent of distribution between binlimits |
exposure_distribution_percent_text_size |
distribution percentages text size default to 5 |
dose_plac_value |
string identifying placebo in DOSE column |
xlab |
text to be used as x axis label |
ylab |
text to be used as y axis label |
points_alpha |
alpha transparency for points |
points_show |
show the 0/1 observations |
prob_obs_byexptile |
observed probability by exptile |
prob_obs_byexptile_group |
additional grouping for exptile probabilities default |
prob_text_size |
probability text size default to 5 |
prob_obs_bydose |
observed probability by dose |
prob_obs_bydose_plac |
observed probability by placebo dose |
Nresp_Ntot |
show N responders/Ntotal ? |
Nresp_Ntot_ypos |
y position for N responders/Ntotal two text elements the first for by exptile and the second
for by dose/color options include |
Nresp_Ntot_sep |
character string to separat N responders/ Ntotal default |
binlimits_show |
show the binlimits vertical lines |
binlimits_text_size |
binlimits text size default to 5 |
binlimits_ypos |
binlimits y position default to 0 |
binlimits_color |
binlimits text color default to "gray70" |
dist_position_scaler |
space occupied by the distribution default to 0.2 |
dist_offset |
offset where the distribution position starts default to 0 |
dist_scale |
scaling parameter for ggridges default to 0.9 |
lineranges_ypos |
where to put the lineranges -1 |
lineranges_dodge |
lineranges vertical dodge value 1 |
lineranges_doselabel |
|
proj_bydose |
project the probabilities on logistic curve |
yproj |
project the probabilities on y axis |
yproj_xpos |
y projection x position 0 |
yproj_dodge |
y projection dodge value 0.2 |
yaxis_position |
where to put y axis "left" or "right" |
facet_formula |
facet formula to be use otherwise |
theme_certara |
apply certara colors and format for strips and default colour/fill |
return_list |
What to return if True a list of the datasets and plot is returned instead of only the plot |
# Example 1 library(ggplot2) effICGI <- logistic_data |> dplyr::filter(!is.na(ICGI))|> dplyr::filter(!is.na(AUC)) effICGI$DOSE <- factor(effICGI$DOSE, levels=c("0", "600", "1200","1800","2400"), labels=c("Placebo", "600 mg", "1200 mg","1800 mg","2400 mg")) effICGI$STUDY <- factor(effICGI$STUDY) effICGI$ICGI2 <- effICGI$ICGI effICGI <- tidyr::gather(effICGI,Endpoint,response,ICGI,ICGI2) gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint=="ICGI"), response = "response", endpoint = "Endpoint", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, exposure_distribution ="distributions", yproj_xpos = -15, yproj_dodge = 10, dist_position_scaler = 0.1, dist_offset = -0.1, Nresp_Ntot_ypos = c("with percentages","bottom"), prob_obs_bydose_plac = FALSE, prob_obs_byexptile_group = "none", binlimits_ypos = -0.08, points_alpha= 1) # Example 2 gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint=="ICGI"), response = "response", endpoint = "Endpoint", exposure_metrics = c("CMAX"), exposure_metric_split = c("tertile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, exposure_distribution ="lineranges", lineranges_ypos = -0.2, lineranges_dodge = 0.2, prob_obs_bydose = TRUE, yproj_xpos = -1, yproj_dodge = 2, dist_position_scaler = 0.1) ## Not run: #' # Example 3 library(ggh4x) gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint=="ICGI"), response = "response", endpoint = "Endpoint", DOSE = "DOSE", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_distribution ="distributions", exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 0.15)+ facet_grid2(Endpoint~expname+DOSE2,scales="free", margins = "DOSE2",strip = strip_nested()) # Example 4 effICGI$SEX <- as.factor(effICGI$SEX) gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint=="ICGI"), response = "response", endpoint = "Endpoint", DOSE = "DOSE", color_fill = "SEX", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_distribution ="distributions", exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, lineranges_ypos = -0.2, yproj_xpos = -10, yproj_dodge = 20, prob_text_size = 6, binlimits_text_size = 6, Nresp_Ntot = TRUE, dist_position_scaler = 0.15)+ ggplot2::scale_x_continuous(breaks = seq(0,350,50), expand = ggplot2::expansion(add= c(0,0),mult=c(0,0)))+ ggplot2::coord_cartesian(xlim = c(-30,355))+ ggplot2::facet_grid(Endpoint~expname+color_fill2, margins ="color_fill2" ) #Example 4b effICGI$SEX <- as.factor(effICGI$SEX) gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint =="ICGI"), response = "response", endpoint = "Endpoint", color_fill = "SEX", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 1, dist_offset = -1 , yproj_xpos = -20 , yproj_dodge = 20 , exposure_distribution ="lineranges") #Example 5 gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint=="ICGI"), response = "response", endpoint = "Endpoint", DOSE = "DOSE", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_distribution ="distributions", exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 0.15)+ facet_grid(Endpoint~expname+exptile,scales="free", margins = "exptile") #Example 6 a <- gglogisticexpdist(data = effICGI, # response = "response", endpoint = "Endpoint", DOSE = "DOSE",yproj_dodge = 36, exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_distribution ="lineranges", exposure_metric_soc_value = -99, exposure_metric_plac_value = 0) + facet_grid(Endpoint~expname,switch = "both") b <- gglogisticexpdist(data = effICGI, # response = "response", endpoint = "Endpoint", DOSE = "DOSE",yproj_dodge = 2, exposure_metrics = c("CMAX"), exposure_metric_split = c("quartile"), exposure_distribution ="lineranges", exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, yaxis_position = "right")+ facet_grid(Endpoint~expname,switch = "x")+ theme(strip.text.y.right = element_blank(), strip.background.y = element_blank()) library(patchwork) (a | b ) + plot_layout(guides = "collect", axes = "collect_x")& theme(legend.position = "top") #Example 7 effICGI <- logistic_data |> dplyr::filter(!is.na(ICGI))|> dplyr::filter(!is.na(AUC)) effICGI$DOSE <- factor(effICGI$DOSE, levels=c("0", "600", "1200","1800","2400"), labels=c("Placebo", "600 mg", "1200 mg","1800 mg","2400 mg")) effICGI$STUDY <- factor(effICGI$STUDY) effICGI$ICGI2 <- ifelse(effICGI$ICGI7 < 4,1,0) effICGI$ICGI3 <- ifelse(effICGI$ICGI7 < 5,1,0) effICGI <- tidyr::gather(effICGI,Endpoint,response,ICGI,ICGI2,ICGI3) effICGI$endpointcol2 <- effICGI$Endpoint gglogisticexpdist(data = effICGI, response = "response", endpoint = "Endpoint", exposure_metrics = c("AUC"), exposure_metric_split = c("median"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, color_fill = "endpointcol2", prob_obs_byexptile = FALSE, logistic_by_color_fill = TRUE, Nresp_Ntot = TRUE, exposure_distribution ="distributions", lineranges_doselabel = TRUE, prob_obs_bydose = TRUE, proj_bydose = FALSE, yproj = FALSE, dist_position_scaler = 0.1, dist_offset = -0.1)+ facet_grid(expname~.,scales="free_x") ## End(Not run)
# Example 1 library(ggplot2) effICGI <- logistic_data |> dplyr::filter(!is.na(ICGI))|> dplyr::filter(!is.na(AUC)) effICGI$DOSE <- factor(effICGI$DOSE, levels=c("0", "600", "1200","1800","2400"), labels=c("Placebo", "600 mg", "1200 mg","1800 mg","2400 mg")) effICGI$STUDY <- factor(effICGI$STUDY) effICGI$ICGI2 <- effICGI$ICGI effICGI <- tidyr::gather(effICGI,Endpoint,response,ICGI,ICGI2) gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint=="ICGI"), response = "response", endpoint = "Endpoint", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, exposure_distribution ="distributions", yproj_xpos = -15, yproj_dodge = 10, dist_position_scaler = 0.1, dist_offset = -0.1, Nresp_Ntot_ypos = c("with percentages","bottom"), prob_obs_bydose_plac = FALSE, prob_obs_byexptile_group = "none", binlimits_ypos = -0.08, points_alpha= 1) # Example 2 gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint=="ICGI"), response = "response", endpoint = "Endpoint", exposure_metrics = c("CMAX"), exposure_metric_split = c("tertile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, exposure_distribution ="lineranges", lineranges_ypos = -0.2, lineranges_dodge = 0.2, prob_obs_bydose = TRUE, yproj_xpos = -1, yproj_dodge = 2, dist_position_scaler = 0.1) ## Not run: #' # Example 3 library(ggh4x) gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint=="ICGI"), response = "response", endpoint = "Endpoint", DOSE = "DOSE", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_distribution ="distributions", exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 0.15)+ facet_grid2(Endpoint~expname+DOSE2,scales="free", margins = "DOSE2",strip = strip_nested()) # Example 4 effICGI$SEX <- as.factor(effICGI$SEX) gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint=="ICGI"), response = "response", endpoint = "Endpoint", DOSE = "DOSE", color_fill = "SEX", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_distribution ="distributions", exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, lineranges_ypos = -0.2, yproj_xpos = -10, yproj_dodge = 20, prob_text_size = 6, binlimits_text_size = 6, Nresp_Ntot = TRUE, dist_position_scaler = 0.15)+ ggplot2::scale_x_continuous(breaks = seq(0,350,50), expand = ggplot2::expansion(add= c(0,0),mult=c(0,0)))+ ggplot2::coord_cartesian(xlim = c(-30,355))+ ggplot2::facet_grid(Endpoint~expname+color_fill2, margins ="color_fill2" ) #Example 4b effICGI$SEX <- as.factor(effICGI$SEX) gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint =="ICGI"), response = "response", endpoint = "Endpoint", color_fill = "SEX", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 1, dist_offset = -1 , yproj_xpos = -20 , yproj_dodge = 20 , exposure_distribution ="lineranges") #Example 5 gglogisticexpdist(data = effICGI |> dplyr::filter(Endpoint=="ICGI"), response = "response", endpoint = "Endpoint", DOSE = "DOSE", exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_distribution ="distributions", exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, dist_position_scaler = 0.15)+ facet_grid(Endpoint~expname+exptile,scales="free", margins = "exptile") #Example 6 a <- gglogisticexpdist(data = effICGI, # response = "response", endpoint = "Endpoint", DOSE = "DOSE",yproj_dodge = 36, exposure_metrics = c("AUC"), exposure_metric_split = c("quartile"), exposure_distribution ="lineranges", exposure_metric_soc_value = -99, exposure_metric_plac_value = 0) + facet_grid(Endpoint~expname,switch = "both") b <- gglogisticexpdist(data = effICGI, # response = "response", endpoint = "Endpoint", DOSE = "DOSE",yproj_dodge = 2, exposure_metrics = c("CMAX"), exposure_metric_split = c("quartile"), exposure_distribution ="lineranges", exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, yaxis_position = "right")+ facet_grid(Endpoint~expname,switch = "x")+ theme(strip.text.y.right = element_blank(), strip.background.y = element_blank()) library(patchwork) (a | b ) + plot_layout(guides = "collect", axes = "collect_x")& theme(legend.position = "top") #Example 7 effICGI <- logistic_data |> dplyr::filter(!is.na(ICGI))|> dplyr::filter(!is.na(AUC)) effICGI$DOSE <- factor(effICGI$DOSE, levels=c("0", "600", "1200","1800","2400"), labels=c("Placebo", "600 mg", "1200 mg","1800 mg","2400 mg")) effICGI$STUDY <- factor(effICGI$STUDY) effICGI$ICGI2 <- ifelse(effICGI$ICGI7 < 4,1,0) effICGI$ICGI3 <- ifelse(effICGI$ICGI7 < 5,1,0) effICGI <- tidyr::gather(effICGI,Endpoint,response,ICGI,ICGI2,ICGI3) effICGI$endpointcol2 <- effICGI$Endpoint gglogisticexpdist(data = effICGI, response = "response", endpoint = "Endpoint", exposure_metrics = c("AUC"), exposure_metric_split = c("median"), exposure_metric_soc_value = -99, exposure_metric_plac_value = 0, color_fill = "endpointcol2", prob_obs_byexptile = FALSE, logistic_by_color_fill = TRUE, Nresp_Ntot = TRUE, exposure_distribution ="distributions", lineranges_doselabel = TRUE, prob_obs_bydose = TRUE, proj_bydose = FALSE, yproj = FALSE, dist_position_scaler = 0.1, dist_offset = -0.1)+ facet_grid(expname~.,scales="free_x") ## End(Not run)
A dataset containing data suitable for logistic regression
logistic_data
logistic_data
A data frame with 600 rows and 10 variables
Study identifier
Subject Identifier
Dose, in mg
Dose, in alternative salt
Sex of the subject
age of the subject, in years
weight of the subject, in kg
Race of the subject
Creatinine clearance
RLS score
RLS score
Area under the curve exposure
Maximun concentration exposure
response 0/1
response 1 to 7
inspired from a real data submission
logistic_data
logistic_data
Run the ggquickeda
application.
run_ggquickeda(data = NULL, ...)
run_ggquickeda(data = NULL, ...)
data |
The initial data.frame to load into the application. |
... |
Additional arguments for bookmarking |
if (interactive()) { run_ggquickeda() }
if (interactive()) { run_ggquickeda() }
A dataset containing concentration-time data with the given dose and some subject characteristics to help in the app exploration.
sample_data
sample_data
A data frame with 600 rows and 10 variables
Subject Identifier, an integer from 1 to 150
Time of dose given or drug sample measured, in hours
dose given at the corresponding Time, in milligrams
drug concentrations in the plasma sample, in mg/L
age of the subject, in years
weight of the subject, in kg
Sex of the subject, a factor with Female and Male levels
Race of the subject, a factor with Asian, Black, Caucasian, Hispanic and Other levels
dose group of the subject, in milligrams
age category of the subject, a variable cutting Age into two values 0/1
"sd_oral_richpk" from 'PKPDmisc' R package with an additional AGECAT variable
sample_data
sample_data
Adds a Kaplan Meier Estimate of Survival
stat_km( mapping = NULL, data = NULL, geom = "km", position = "identity", show.legend = NA, inherit.aes = TRUE, trans = scales::identity_trans(), firstx = 0, firsty = 1, type = "kaplan-meier", start.time = 0, ... )
stat_km( mapping = NULL, data = NULL, geom = "km", position = "identity", show.legend = NA, inherit.aes = TRUE, trans = scales::identity_trans(), firstx = 0, firsty = 1, type = "kaplan-meier", start.time = 0, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
trans |
Transformation to apply to the survival probabilities. Defaults to "identity". Other options include "event", "cumhaz", "cloglog", or define your own using trans_new. |
firstx , firsty
|
the starting point for the survival curves. By default,
the plot program obeys tradition by having the plot start at |
type |
an older argument that combined stype and ctype, now deprecated. Legal values were "kaplan-meier" which is equivalent to stype=1, ctype=1, "fleming-harrington" which is equivalent to stype=2, ctype=1, and "fh2" which is equivalent to stype=2, ctype=2. |
start.time |
numeric value specifying a time to start calculating survival information. The resulting curve is the survival conditional on surviving to start.time. |
... |
Other arguments passed to survfit.formula |
This stat is for computing the confidence intervals for the Kaplan-Meier survival estimate for
right-censored data. It requires the aesthetic mapping x
for the
observation times and status
which indicates the event status,
0=alive, 1=dead or 1/2 (2=death). Logical status is not supported.
a data.frame with additional columns:
x |
x in data |
y |
Kaplan-Meier Survival Estimate at x |
stat_km
understands the following aesthetics (required aesthetics
are in bold):
time
The survival times
status
The censoring indicator, see Surv for more information.
alpha
color
linetype
size
library(ggplot2) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex))) + stat_km() ## Examples illustrating the options passed to survfit.formula p1 <- ggplot(df, aes(time = time, status = status)) p1 + stat_km() p1 + stat_km(trans = "cumhaz") # for cloglog plots also log transform the time axis p1 + stat_km(trans = "cloglog") + scale_x_log10() p1 + stat_km(type = "fleming-harrington") p1 + stat_km(start.time = 5)
library(ggplot2) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex))) + stat_km() ## Examples illustrating the options passed to survfit.formula p1 <- ggplot(df, aes(time = time, status = status)) p1 + stat_km() p1 + stat_km(trans = "cumhaz") # for cloglog plots also log transform the time axis p1 + stat_km(trans = "cloglog") + scale_x_log10() p1 + stat_km(type = "fleming-harrington") p1 + stat_km(start.time = 5)
Adds confidence bands to a Kaplan Meier Estimate of Survival
stat_kmband( mapping = NULL, data = NULL, geom = "kmband", position = "identity", show.legend = NA, inherit.aes = TRUE, trans = "identity", firstx = 0, firsty = 1, type = "kaplan-meier", error = "greenwood", conf.type = "log", conf.lower = "usual", start.time = 0, conf.int = 0.95, ... )
stat_kmband( mapping = NULL, data = NULL, geom = "kmband", position = "identity", show.legend = NA, inherit.aes = TRUE, trans = "identity", firstx = 0, firsty = 1, type = "kaplan-meier", error = "greenwood", conf.type = "log", conf.lower = "usual", start.time = 0, conf.int = 0.95, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
trans |
Transformation to apply to the survival probabilities. Defaults
to "identity". Other options include "event", "cumhaz", "cloglog", or
define your own using |
firstx , firsty
|
the starting point for the survival curves. By default, the plot program obeys tradition by having the plot start at (0,1). |
type |
an older argument that combined stype and ctype, now deprecated. Legal values were "kaplan-meier" which is equivalent to stype=1, ctype=1, "fleming-harrington" which is equivalent to stype=2, ctype=1, and "fh2" which is equivalent to stype=2, ctype=2. |
error |
either the string "greenwood" for the Greenwood formula or "tsiatis" for the Tsiatis formula, (only the first character is necessary). The default is "greenwood". |
conf.type |
One of "none", "plain", "log" (the default), "log-log" or "logit". |
conf.lower |
a character string to specify modified lower limits to the curve, the upper limit remains unchanged. Possible values are "usual" (unmodified), "peto", and "modified". The modified lower limit is based on an "effective n" argument. The confidence bands will agree with the usual calculation at each death time, but unlike the usual bands the confidence interval becomes wider at each censored observation. The extra width is obtained by multiplying the usual variance by a factor m/n, where n is the number currently at risk and m is the number at risk at the last death time. (The bands thus agree with the un-modified bands at each death time.) This is especially useful for survival curves with a long flat tail. The Peto lower limit is based on the same "effective n" argument as the modified limit, but also replaces the usual Greenwood variance term with a simple approximation. It is known to be conservative. |
start.time |
numeric value specifying a time to start calculating survival information. The resulting curve is the survival conditional on surviving to start.time. |
conf.int |
the level for a two-sided confidence interval on the survival curve(s). Default is 0.95. |
... |
Other arguments passed to survfit.formula |
This stat is for computing the confidence intervals for the Kaplan-Meier survival estimate for
right-censored data. It requires the aesthetic mapping x
for the
observation times and status
which indicates the event status,
0=alive, 1=dead or 1/2 (2=death). Logical status is not supported.
a data.frame with additional columns:
x |
x in data |
ymin |
Lower confidence limit of KM curve |
ymax |
Upper confidence limit of KM curve |
stat_kmband
understands the following aesthetics (required aesthetics
are in bold):
time
The survival times
status
The censoring indicator, see Surv for more information.
alpha
color
linetype
linewidth
library(ggplot2) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex))) + stat_km() ## Examples illustrating the options passed to survfit.formula p1 <- ggplot(df, aes(time = time, status = status)) p1 + stat_km() + stat_kmband(conf.int = .99) p1 + stat_kmband(error = "greenwood",fill="red",alpha=0.2) + stat_kmband(error = "tsiatis",fill="blue",alpha=0.2)+ stat_km() p1 + stat_km() + stat_kmband(conf.type = "log-log")+ stat_kmband(conf.type = "log")
library(ggplot2) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex))) + stat_km() ## Examples illustrating the options passed to survfit.formula p1 <- ggplot(df, aes(time = time, status = status)) p1 + stat_km() + stat_kmband(conf.int = .99) p1 + stat_kmband(error = "greenwood",fill="red",alpha=0.2) + stat_kmband(error = "tsiatis",fill="blue",alpha=0.2)+ stat_km() p1 + stat_km() + stat_kmband(conf.type = "log-log")+ stat_kmband(conf.type = "log")
Adds tick marks to a Kaplan Meier Estimate of Survival
stat_kmticks( mapping = NULL, data = NULL, geom = "kmticks", position = "identity", show.legend = NA, inherit.aes = TRUE, trans, ... )
stat_kmticks( mapping = NULL, data = NULL, geom = "kmticks", position = "identity", show.legend = NA, inherit.aes = TRUE, trans, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
trans |
Transformation to apply to the survival probabilities. Defaults to "identity". Other options include "event", "cumhaz", "cloglog", or define your own using trans_new. |
... |
Other arguments passed to survfit.formula |
This stat is for computing the tick marks for a Kaplan-Meier survival estimate for
right-censored data. The tick marks will appear at each censoring time which is also
not a death time, which is the default for plot.survfit.
It requires the aesthetic mapping x
for the
observation times and status
which indicates the event status,
normally 0=alive, 1=dead. Other choices are TRUE/FALSE (TRUE = death) or 1/2
(2=death).
a data.frame with additional columns:
x |
x in data |
y |
Kaplan-Meier Survival Estimate at x |
stat_kmticks
understands the following aesthetics (required aesthetics
are in bold):
time
The survival times
status
The censoring indicator, see Surv for more information.
alpha
color
linetype
size
library(ggplot2) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex))) + stat_km() + stat_kmticks()
library(ggplot2) sex <- rbinom(250, 1, .5) df <- data.frame(time = exp(rnorm(250, mean = sex)), status = rbinom(250, 1, .75), sex = sex) ggplot(df, aes(time = time, status = status, color = factor(sex))) + stat_km() + stat_kmticks()