How to plot the Hazard Ratio + CI over time of survival data in ggplot in R?
I want to plot the hazard ratio over time, including its confidence intervals, of a survival dataset. As an example, I will take a simplified dataset from the
survival package: the colon dataset.
library(survival) library(tidyverse) # Colon survival dataset data <- colon %>% filter(etype == 2) %>% select(c(id, rx, status, time)) %>% filter(rx == "Obs" | rx == "Lev+5FU") %>% mutate(rx = factor(rx))
The dataset contains patients that received a treatment (i.e., "Lev+5FU") and patients that did not (i.e., "Obs"). The survival curves are as follows:
fit <- survfit(Surv(time, status) ~ rx, data = data ) plot(fit)
cox.zph function, you can plot the hazard ratio of a cox model.
cox <- coxph(Surv(time, status) ~ rx, data = data) plot(cox.zph(cox))
However, I want to plot the hazard ratio including 95% CI for this survival dataset using
- How do you extract the hazard ratio data and the 95% CIs from this cox.zph object to plot them in
- Are there other
Rpackages that enable doing the same in a more convenient way?
survminer package will do this for you:
Answered By – MånsT