Open jvanlunenburg opened 4 years ago
Update: I discovered the ggadjustedcurve
function was made for this purpose. The only example I found used outdated syntax, but I eventually got it working after finding out that data
can't be a tibble (got a cryptic sorting bug).
I just don't understand why another function was necessary, ideally I'd just pass my coxph
object to ggsurvplot
.
I found this thread after attempting to customize my coxph plot and realizing that it doesn't seem possible to use the facet.by=" " or ggsurvplot_facet_by() functions when plotting a coxph model.
My goal is to display a curve for each genotype (WT, Tg) on the same plot (as shown below), and then "facet" by sex, so I have a mini-panel for Males (with WT, Tg shown), and another panel for females (also showing curves for WT and Tg). I could show all four groups (WTM, WTF, TgM, TgF) on the same plot, but it is messy so I'd like to try to split them. It seems as though the ggadjustedcurve function is made for plotting adjusted coxph models, but doesn't support the facet.by functionality.
The model I want to plot, along with my attempt to plot it, are shown here:
coxplot_geno0 = coxph(Surv(latency,success) ~ strata(genotype) + sex + age + speed + trial, data = df2_geno0)
ggsurvplot(surv_fit(coxplot_geno0, data = df2_geno0),
conf.int=TRUE, conf.int.alpha=0.15,
fun = "event", surv.median.line = "hv", cumevents = FALSE, cumcensor = FALSE,
palette = mycolours_geno, xlim=c(0,180), break.time.by=30, surv.scale = "percent",
ggtheme = theme_classic(base_size = 14), legend.title ="") +
labs(x = "Time(s)", y = "Proportion Escaped", title = "Timepoint 0 - 4 months")
Thanks very much!!
I'm having trouble plotting the survival curves for a 2-group factor (sex) using the
coxph
fit.The above gives a single line for overall survival. I want 2 lines, one per group.
group.by = c("sex")
it results in an error:survfit(Surv(time = event.days, event = outcome.status) ~ sex, data = df)
but this is sub-optimal: