Skip to content

Commit

Permalink
Updated scipts to create worse versions of the figures with no riskta…
Browse files Browse the repository at this point in the history
…bles. Simplicity.
  • Loading branch information
alexpaynter committed Jan 27, 2025
1 parent ea0aac0 commit 0afe87f
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
55 changes: 55 additions & 0 deletions R/plot_one_survfit_no_risktable.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

plot_one_survfit_no_risktable <- function(
dat,
surv_form,
pal = c('#bb5566', '#004488', '#ddaa33'),
plot_title = NULL,
plot_subtitle = NULL,
x_title = "Years",
x_exp = 0.15,
x_breaks = seq(0, 100, by = 2.5),
force_color = NULL
) {

gg <- survfit2(surv_form, data = dat)

# couldn't figure out how to do this without an if/else, sadly.
if (!is.null(force_color)) {
gg %<>% ggsurvfit(color = force_color)
} else {
gg %<>% ggsurvfit()
}

gg <- gg +
scale_y_continuous(
expand = c(0,0),
label = scales::label_percent(),
name = "Survival"
) +
scale_x_continuous(
name = x_title,
expand = expansion(add = 0, mult = c(0, x_exp)), # needed to prevent clipping
breaks = x_breaks
) +
scale_color_manual(
values = pal
) +
coord_cartesian(
xlim = c(0, NA),
ylim = c(0,1.01),
expand = T
) +
labs(
title = plot_title,
subtitle = plot_subtitle
) +
theme(
axis.title.y = element_blank(),
plot.title.position = "plot",
title = element_markdown(),
# prevents the axis tick label clipping:
plot.margin=unit(c(.2,.2,.2,.2),"cm")
)

return(gg)
}
57 changes: 57 additions & 0 deletions analysis/script/create_2025_asco_gu_abtract_figures.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Creates an output versions of figures for GU ASCO 2025 submission poster.

library(purrr); library(fs); library(here);
purrr::walk(.x = fs::dir_ls(here('R')), .f = source)

dir_out <- here('output', 'fig', 'manu')

os_by_stage <- readr::read_rds(
file = here('data', 'survival', 'os_dx_by_stage_manu.rds')
)

first_line_platinum <- readr::read_rds(
file = here('data', 'survival', 'first_line_platinum', 'gg_first_line_platinum.rds')
)

first_line_by_ddr <- readr::read_rds(
file = here('data', 'survival', 'ddr_onco',
'gg_met_ddr_manu.rds')
)

first_line_by_ddr_plat <- readr::read_rds(
file = here('data', 'survival', 'ddr_onco',
'gg_met_ddr_plat_split.rds')
)

second_line_by_ddr_io <- readr::read_rds(
file = here('data', 'survival', 'ddr_onco',
'gg_os_2l_io_ddr.rds')
)



fig1_comb <- plot_grid(
ggsurvfit_build(os_by_stage),
ggsurvfit_build(first_line_platinum),
ggsurvfit_build(first_line_by_ddr),
ggsurvfit_build(first_line_by_ddr_plat),
ggsurvfit_build(second_line_by_ddr_io),
labels = "AUTO",
align = 'hv',
axis = 't',
ncol = 2
)



ggsave(
plot = fig1_comb,
filename = here(dir_out, 'fig1.pdf'),
height = 7.5, width = 7, scale = 1.8
)

ggsave(
plot = fig1_comb,
filename = here(dir_out, 'fig1.png'),
height = 7.5, width = 7, scale = 1.8
)
27 changes: 27 additions & 0 deletions analysis/script/surv_ddr_asco_2025_io.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ dft_cohort_ddr %>%
select(-record_id) %>%
gtsummary::tbl_summary(.)

dft_met_ddr_surv_grouped %>%
mutate(
pt_counts = purrr::map(
.x = data,
.f = \(x) count(x, ddr_before_entry)
)
) %>%
select(analysis_group, pt_counts) %>%
unnest(pt_counts)

dft_met_ddr_surv_grouped %>%
select(analysis_group, cox_ddr) %>%
unnest(cox_ddr) %>%
Expand Down Expand Up @@ -377,7 +387,24 @@ gg_os_2l_io_ddr <- plot_one_survfit(
x_exp = 0.05
)

# A no-risktable version for the poster.
gg_os_2l_io_ddr_no_rt <- plot_one_survfit_no_risktable(
dat = dft_met_ddr_surv,
surv_form = surv_obj_os_fmr ~ ddr_disp,
plot_title = "OS from second line pembrolizumab or atezolizumab",
plot_subtitle = "Adjusted for (independent) delayed entry",
x_breaks = seq(0, 10, by = 0.5),
x_exp = 0.05
)


readr::write_rds(
gg_os_2l_io_ddr,
here('data', 'survival', 'ddr_onco', 'gg_os_2l_io_ddr.rds')
)

readr::write_rds(
gg_os_2l_io_ddr_no_rt,
here('data', 'survival', 'ddr_onco', 'gg_os_2l_io_ddr_no_rt.rds')
)

33 changes: 32 additions & 1 deletion analysis/script/surv_ddr_onco_plat.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,25 @@ gg_os_fmr_ddr_manu <- plot_one_survfit(
coord_cartesian(xlim = c(0,5)) +
theme(plot.title.position = 'panel')

gg_os_fmr_ddr_manu_no_rt <- plot_one_survfit_no_risktable(
dat = dft_met_ddr_surv,
surv_form = surv_obj_os_fmr ~ ddr_disp,
plot_title = "OS from first line platinum chemo",
x_breaks = seq(0, 100, by = 0.5)
) +
coord_cartesian(xlim = c(0,5)) +
theme(plot.title.position = 'panel')

readr::write_rds(
gg_os_fmr_ddr_manu,
file = here(dir_out, "gg_met_ddr_manu.rds")
)

readr::write_rds(
gg_os_fmr_ddr_manu_no_rt,
file = here(dir_out, "gg_met_ddr_manu_no_rt.rds")
)

ggsave(
plot = gg_os_fmr_ddr_manu,
height = 4, width = 7,
Expand Down Expand Up @@ -351,13 +365,30 @@ gg_os_fmr_ddr_manu_plat_split <- plot_one_survfit(
coord_cartesian(xlim = c(0,5)) +
theme(plot.title.position = 'panel')

gg_os_fmr_ddr_manu_plat_split
gg_os_fmr_ddr_manu_plat_split_no_rt <- plot_one_survfit_no_risktable(
dat = dft_met_ddr_surv,
surv_form = surv_obj_os_fmr ~ ddr_plat_comb,
plot_title = "OS from first line platinum chemo",
x_breaks = seq(0, 100, by = 0.5),
pal = c("#ee99aa", "#994455", "#6699cc", "#004488")
) +
coord_cartesian(xlim = c(0,5)) +
theme(plot.title.position = 'panel')

gg_os_fmr_ddr_manu_plat_split_no_rt


readr::write_rds(
gg_os_fmr_ddr_manu_plat_split,
file = here(dir_out, "gg_met_ddr_plat_split.rds")
)

readr::write_rds(
gg_os_fmr_ddr_manu_plat_split_no_rt,
file = here(dir_out, "gg_met_ddr_plat_split_no_rt.rds")
)





Expand Down

0 comments on commit 0afe87f

Please sign in to comment.