# [R] Printing output on Plot

Austin, Matt maustin at amgen.com
Fri Sep 3 04:53:19 CEST 2004

```The following example should get you started.

library(survival)
test1 <- list(time=  c(4, 3,1,1,2,2,3),
status=c(1,NA,1,0,1,1,0),
x=     c(0, 2,1,1,1,0,0),
sex=   c(0, 0,0,0,1,1,1))
cpfit <- coxph( Surv(time, status) ~ x + strata(sex), test1)  #stratified
model

cpfit

pval <- paste("P-value: ", round(1 -
pchisq((cpfit\$coef/sqrt(diag(cpfit\$var)))^2, 1), 3))
plot(survfit(cpfit))

--Matt

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Neil Leonard
Sent: Thursday, September 02, 2004 19:12 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Printing output on Plot

Hi,

I'm trying to print the p-values from the output of a CPH test onto a
Kaplan Meier plot. Can this be done? I only really want the p-values
from the CPH test to appear but if this can't be done I am willing to
have the entire CPH output.

This is what I am currently trying: (it doesn't print the CPH output)

plot_KM <- function(field)
{
library(survival)
y = length(levels(factor(field)))
field.KM <- survfit(Surv(age_at_death,death)~field)
field.CPH <- coxph(Surv(age_at_death,death)~factor(field))
plot(field.KM,mark.time=FALSE,col=2:
(y+1),lty=1,main=paste(as.character(substitute(field))," Kaplan-Meier
Plot"))
text(1000, .3, paste(as.character(field.CPH)), col="red")
legend(1000, .5, levels(factor(field)), col=2:(y+1), lty=1)
}

Thanks,
Neil

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help