将文本添加到受限三次样条图

Addnig text to restricted cubic splines plot

我有以下假设数据来绘制受限三次样条曲线

library(rms)
library(survival)
n <- 1000
set.seed(731)
age <- 50 + 12*rnorm(n)
label(age) <- "Age"
sex <- factor(sample(c('Male','Female'), n, rep=TRUE, prob=c(.6, .4)))
cens <- 15*runif(n)
h <- .02*exp(.04*(age-50)+.8*(sex=='Female'))
dt <- -log(runif(n))/h
label(dt) <- 'Follow-up Time'
e <- ifelse(dt <= cens,1,0)
dt <- pmin(dt, cens)
units(dt) <- "Year"
dd <- datadist(age, sex)
options(datadist='dd')
S <- Surv(dt,e)

f <- cph(S ~ rcs(age,4) + sex, x=TRUE, y=TRUE)
cox.zph(f, "rank")             # tests of PH
anova(f)
plot(Predict(f, age, sex)) # plot age effect, 2 curves for 2 sexes

根据以上数据,我得到了这个精美的情节:

我想向其中添加以下文本 text(60,-1,"p < 0.001"),但它不起作用并给我以下错误消息:plot.new has not been called yet。任何想法可能是什么问题?我可以通过其他方式向其中添加文本(或图例)吗?

rms 包移动到点阵绘图平台。您需要在面板调用或补充晶格函数之一中添加文本。请参阅 ?llines 或使用 trellis.focus.

[![ap <- function(...) { ltext(60, 1, "p < 0.001") }

plot(Predict(f, age, sex), addpanel=ap)][1]][1]