How to add Hazard ratio value into Kaplan Meier plot?
1
1
Entering edit mode
4.4 years ago
Raheleh ▴ 260

Hi, I plot the KM for my data. This is the script:

ggsurvplot(survfit(recsurv~T1_signature, data = MSKCC), size = 1,  
           palette = c("#E7B800", "#2E9FDF"),  
           conf.int = FALSE, 
           pval = TRUE,  
           risk.table = TRUE, 
           risk.table.col = "strata",
           # Risk table color by groups 
           ggtheme = theme_bw()+theme(plot.title = element_text(hjust = 0.5), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
            panel.background = element_blank()))

and this is the plot:

enter image description here

I calculated the HR and it is 9.3. I want to include it in the plot. Anyone knows how to do it?

Many thanks!!

kaplan meier Hazard Ratio r ggsurvplot • 7.7k views
ADD COMMENT
0
Entering edit mode

Once we know that ggsurvplot is a wrapper for the ggplot2, then we can do any customisation using:

mySurvPlot <- ggsurvplot(...)
mySurvPlot$plot <- mySurvPlot$plot +
  # customise
  geom_text(...) +
  etc...

#then plot
mySurvPlot
ADD REPLY
3
Entering edit mode
4.4 years ago

Something like this:

library(ggplot2)
library(survival)
library(survminer)

fit <- survfit(Surv(time, status) ~ sex, data = lung)
ggsurv <- ggsurvplot(fit, risk.table = TRUE)

# customised the plot
ggsurv$plot <- ggsurv$plot +
  ggplot2::annotate(
    "text",
    x = Inf, y = Inf,
    vjust = 1, hjust = 1,
    label = "HR = 0.9 \n p < 0.001",
    size = 5
  )

# now plot
ggsurv

Rplot02

Modified from GitHub_survminer_issues_54. Change x, y coordinates. If you are hard coding p-value in label, change pvalue to false from true. If you want to keep pvalue = TRUE, do not add p-value to annotate function. In later case, alignment would be a problem between p-value and HR text.

ADD COMMENT
0
Entering edit mode

Thank you cpad. I want to have risk table as well. I already tried to do it by annotate function. However, when I use annotate, risk table goes. Do you know how to keep risk table and HR together? Thank you!

ADD REPLY
0
Entering edit mode

@Raheleh Edited: first we need to update the plot, then plot. This way it will plot the risk tables, too.

ADD REPLY

Login before adding your answer.

Traffic: 2693 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6