I’m trying to change the text color inside the add_risktable()
function in ggsurvfit so that each strata in the risk table matches the same strata’s color in the ggcuminc plot. The function in ggsurvplot that does this is risk.table.col = "strata"
but I haven’t figured out how to get that result to work in ggcuminc/ggsurvfit. This is my current code setup in my R shiny app.
if ("Risk Table" %in% input$rrOpt) {
RT <- add_risktable(risktable_stats = "n.risk",
stats_label = list(n.risk = "Number at Risk"),
risktable_height = 0.3,
size = 4.5,
theme = theme_risktable_default(axis.text.y.size = 12, plot.title.size = 12))
} else {
RT <- NULL
}
rrfit <- survfit2(Surv(`Years RR from CR EOI1`, `EFS event ID`) ~ Risk, data = combined_data) %>%
ggcuminc(outcome = 'Relapse',
theme = theme_minimal(),
size = 1,
linetype_aes = TRUE) +
labs(
x = "Years",
y = "Cumulative Incidence"
) +
coord_cartesian(ylim = c(0,1)) +
RT +
scale_color_manual(values = palette_vector) +
scale_linetype_manual(values = linetype_vector) +
scale_x_continuous(limits=c(0,5),
breaks=seq(from=0,
to=5,
by=1)) +
add_legend_title(title = paste(legend_vector1, "n:", sample_vector, collapse = "n"))
if (CI == TRUE) {
rrfit <- rrfit + add_confidence_interval()
rrfit <- rrfit + scale_fill_manual(values = palette_vector)
}
else {
rrfit <- rrfit
}
if (!is.null(pval) && pval != FALSE) {
pval_text <- paste(pval)
rrfit <- rrfit + annotate("text", x = 0.1, y = 0.83, label = pval_text, size = 4, hjust = 0)
}
rrfit <- ggpar(rrfit,
font.x = 12,
font.y = 12,
font.caption = 12,
font.legend = 12,
font.tickslab = 12)
I’ve tried using the theme() function to get this to work but to no avail. The documentation for cmprsk doesn’t appear to have a solution either, even though I know there must be one.
This worked with ggsurvplot
This is what ggcuminc looks like right now