Home > Blockchain >  How to extract y-axis value on R plot?
How to extract y-axis value on R plot?

Time:11-01

enter image description here

Hi all, I have this plot above. I want to extract the y-axis value (cumulative hazard %) to find the hazard at the END of the follow-up period between smokers and non-smokers. Here is my code that I used to create the plot:

survmod1 <- survfit(Surv(timedth, death)~cursmoke, data=frmgham_recoded,
                    conf.type="log-log") #force confidence intervals to be bounded between 0 and 1

plot(survmod1, 
     main="Kaplan-Meier Failure Estimates by smoking status",
     xlab="Time (days)", ylab="Cumulative Hazard", 
     fun="event", #transforms data into failure event function, plots the complement
     bty="l", col=c("darkblue","darkorange"))
         
legend("bottomright",legend=c("no","yes"),
       lty=1, lwd=2, 
       col=c("darkblue","darkorange"),
       cex=0.8,bty="o")

CodePudding user response:

It looks to me like you survfit object contains the cumulative hazard data already. Try survmod1$cumhaz to get these data.

CodePudding user response:

Try: This should give you time n.risk n.event survival std.err lower 95% CI upper 95% CI. You could tweak the times sequence as you need.

library(survival) 
library(survminer)
summary(survmod1, times = seq(0, 8000, 2000))
  •  Tags:  
  • r
  • Related