Question: How to add Hazard ratio value into Kaplan Meier plot?
gravatar for Rahil
9 months ago by
Rahil170 wrote:

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"),  
  = 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!!

ADD COMMENTlink modified 9 months ago • written 9 months ago by Rahil170

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(...) +

#then plot
ADD REPLYlink written 9 months ago by zx87549.6k
gravatar for cpad0112
9 months ago by
cpad011214k wrote:

Something like this:


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

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

# now plot


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 COMMENTlink modified 9 months ago by zx87549.6k • written 9 months ago by cpad011214k

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 REPLYlink written 9 months ago by Rahil170

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

ADD REPLYlink written 9 months ago by zx87549.6k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1103 users visited in the last hour