0
votes

Background

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)

enter image description here

Attempt

Using the 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))

enter image description here

However, I want to plot the hazard ratio including 95% CI for this survival dataset using ggplot.

Question(s)

  1. How do you extract the hazard ratio data and the 95% CIs from this cox.zph object to plot them in ggplot?
  2. Are there other R packages that enable doing the same in a more convenient way?
1

1 Answers

1
votes

The survminer package will do this for you:

library(survminer)
ggcoxzph(cox.zph(cox))