I'd like to edit the y-axis titles of my Schoenfeld residuals plot, which currently say, "Beta(t) for [variable name]" where [variable name] is the variable's data entry name rather than its label name. For instance, I'd like to change "Beta(t) for exposure" in the following plot to "Beta(t) for Mortality" and "Beta(t) for PROBLEMUse" to "Beta(t) for Problematic Substance Use". Is this possible?
mod.full <- coxph(Surv(Time, outcome) ~ exposure + ., md)
ggcoxzph(cox.zph(mod.full), point.size = 1, ggtheme = theme_classic() + customization_sr)
First of all I used some reproducible data from the package. Since these are ggplot objects you could use the ggplot_build
function to modify layers and labels. So you could use this to change the y label like this:
library(survival)
library(survminer)
fit <- coxph(Surv(futime, fustat) ~ age + ecog.ps + rx, data=ovarian)
cox.zph.fit <- cox.zph(fit)
p <- ggcoxzph(cox.zph.fit, point.size = 1, ggtheme = theme_classic())
p1 <- p$`1`
q1 <- ggplot_build(p1)
q1$plot$labels$y = "Beta(t) for Mortality"
q1 <- ggplot_gtable(q1)
plot(q1)
Created on 2023-04-19 with reprex v2.0.2
As you can see the y axis title has been changed.