# Plot of the estimated log hazard ratio in R

Is it possible to plot the estimated log hazard ratio in R? For example,

require(survival)
fit1 = coxph(Surv(futime, fustat) ~ rx, ovarian)

• Plot it how? Over time? By covariates? Just a picture of the distribution of the HR? Commented Sep 23, 2011 at 1:51
• Isn't the estimated hazard ratio just one number? Do you instead want a plot of the estimated baseline hazard?
– Karl
Commented Sep 23, 2011 at 3:34
• I try to reproduce a similar figure on "Applied Survival Analysis" (Page 117, Figure 4.2). I believe that the authors plots the estimated log hazard ration over time.
– Tu.2
Commented Sep 23, 2011 at 16:50

Saw this question while browsing through the survival questions and though I just post some of my personal favorites. I like using the rms package for survival functions and you could do a forestplot type of output:

library(survival)
library(rms)

ovarian$rx <- factor(ovarian$rx)
fit1 = cph(Surv(futime, fustat) ~ rx + rcs(age, 3), ovarian, x=T, y=T)
# The plot.summary.rms
plot(summary(fit1, age=c(50,60)), q=c(.6, .8, .95), log=T,
col=c("orange", "gold", "blue"))


gives you:

I also like the termplot that I've updated slightly:

par(mfrow=c(1,2))
termplot2(fit1, se=T, rug.type="density", rug=T, density.proportion=.05,
se.type="polygon",
ylab=rep("Hazard Ratio", times=2),
main=rep("cph() plot", times=2),
col.se=rgb(.2,.2,1,.4), col.term="black")


that gives you this plot:

and last but not least for a log-log plot if you wanted to look for the hazard over time as the comment suggested:

f <- survfit(Surv(futime, fustat) ~ rx, data=ovarian)
survplot(f, loglog=T, logt=T, xlab="log(Years)")


that gives:

another efficient way of looking at the hazard of time is the Schoenfeld residuals:

layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE))
f <- cox.zph(fit1)
plot(f, resid=F)


that gives:

Not having a copy of Applied Survival Analysis, I'm guessing you're looking for something like this: http://rgm2.lab.nig.ac.jp/RGM2/func.php?rd_id=Design:hazard.ratio.plot