Question: How to add Hazard ratio value into Kaplan Meier plot?
1
gravatar for Raheleh
4 months ago by
Raheleh140
Raheleh140 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"),  
           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!!

ADD COMMENTlink modified 4 months ago • written 4 months ago by Raheleh140

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 REPLYlink written 4 months ago by zx87549.1k
3
gravatar for cpad0112
4 months ago by
cpad011212k
India
cpad011212k wrote:

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 COMMENTlink modified 4 months ago by zx87549.1k • written 4 months ago by cpad011212k

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 4 months ago by Raheleh140

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

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

Help
Access

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