show_cif: show_cif

View source: R/event_time_desp.R

show_cifR Documentation

show_cif

Description

show_cif

Usage

show_cif(
  surv_obj,
  evt_type = 1,
  evt_label = function(x) {     recode_factor(x, `1` = "Event", `2` =
    "Competing event", .default = "Event free") },
  add_ci = TRUE,
  add_atrisk = TRUE,
  add_legend = FALSE,
  add_pvalue = TRUE,
  atrisk_init_pos = NULL,
  pvalue_pos = c("bottomright", "topleft", "topright", "bottomleft", "left", "right",
    "top", "bottom"),
  plot_theme = theme_minimal(),
  x_lab = "Time",
  y_lab = "Proportion of subjects",
  x_lim = NULL,
  y_lim = NULL,
  x_break = NULL,
  y_break = NULL,
  color_scheme = c("brewer", "grey", "viridis", "manual"),
  color_list = NULL,
  plot_cdf = FALSE
)

Arguments

surv_obj

a survfitms subject.

add_ci

an integer vector indicating right censoring (0= censored; 1= event of interest; other= competing risk(s)).

add_atrisk

a logical parameter indicating whether at-risk table should be added to the figure.

add_legend

a logical parameter indicating whether legend should be added to the figure.

add_pvalue

a logical parameter (default= FALSE) indiciates if a p-value should be added to the plot.

pvalue_pos

a character parameter indicating where the p-value should be added to the plot.

plot_theme

a numeric vector recording the time points at which the event occurs.

x_lab

an integer vector indicating right censoring (0= censored; 1= event of interest; other= competing risk(s)).

y_lab

a numeric vector specifying the time point at which administrative censoring is applied.

x_lim

a numeric vector specifying the time point at which administrative censoring is applied.

y_lim

a logical scalar (default= FALSE) indiciates if the existing time-to-event variables should be overwritten.

color_list

input data

plot_cdf

Not used

Details

The function shows the cumulative incidence function for competing risks with and without strata.

Value

A ggplot object.

Examples

my_plot_theme<- theme_bw() +
theme(axis.title  = element_text(size= 14, family="Arial"),
      axis.title.x= element_text(margin= unit(c(t= 1, r = 0, b = 0, l = 0), "lines"), family="Arial"),
      axis.title.y= element_text(margin= unit(c(t= 0, r = 1, b = 0, l = 0), "lines"), family="Arial"),
      axis.text   = element_text(size= 12, family="Arial"),
      # set the axis line (i.e. bty= "l" in traditional plot)
      axis.line.x = element_line(color="black", size = 1),
      axis.line.y = element_line(color="black", size = 1),

      # specify the legend (e.g. position, color, justification)
      legend.title= element_blank(),
      legend.background= element_rect(fill= "transparent"),
      legend.text      = element_text(family= "Arial", size = 12),
      legend.margin    = margin(t = 0, r = 0, b = 0, l = 0,"bigpts"),
      legend.key       = element_rect(fill= "transparent", color= "transparent", linetype= "blank"),
      legend.key.size  = unit(24, "bigpts"),
      # legend.position= c(0.98, 0.02),
      # legend.justification= c(1, 0),

      #eliminates background, gridlines, and chart border
      panel.border = element_blank(),
      # plot.background = element_blank(),
      # panel.grid.major = element_blank(),
      panel.grid.minor = element_blank(),
      panel.spacing = unit(1, "lines"),

      strip.background = element_rect(fill = "black", color= "white"),
      strip.text = element_text(family = "Arial", color= "white", size = 12, face= "bold"),

      # plot margin. Sufficient margins must be specified for printing at-risk patients.
      plot.margin= unit(c(top= 0.1, right= 0.05, bottom= .3, left= .2), "npc"))

# read in the example data
cmprisk_df<- read.csv2("http://www.stat.unipg.it/luca/misc/bmt.csv")
admin_censor_cmprisk(cmprisk_df, ftime, status, evt_label = c("0"= "Event free", "1"= "Event", "2"= "Competing event"), adm_cnr_time= 10)
p<- cmprisk_df %>%
admin_censor_cmprisk(ftime, status,
                     adm_cnr_time= 30,
                     overwrite_var = TRUE) %>%
  estimate_cif(ftime, status) %>%
  show_cif(evt_type = 1,
           plot_theme= my_plot_theme,
           x_break= seq(0, 10, by= 1),
           y_break= seq(0, .8, by= .1),
           add_pvalue = TRUE,
           add_atrisk = TRUE,
           add_ci = TRUE,
           add_legend = FALSE,
           color_scheme = "manual",
           color_list = list(values= c('blue', 'blue')),
           pvalue_pos= "topleft")

#---- To show the at risk information ----
gt <- ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name == 'panel'] <- "off"
grid.draw(gt)

fanstev1/fanetc documentation built on April 17, 2025, 10:58 a.m.