I am working with survival analysis and the smoothHR package, after modeling I'd like to plot the relative risk vs a variable, thing that is quite easy with
plot(dataset, predictor)
But I'd like to do it using the ggplot package. Any idea how to?
#the library
library(smoothHR)
#the artificial dataset
surv.days<- runif(n = 200, min = 100, max = 500)
censor<- sample(c(0,1), 200, replace=TRUE)
surv.var<- surv.days/10 + rnorm(200, mean = 0, sd = 3)
surv.var[which(surv.days>250)]<- surv.days[which(surv.days>250)]/5 + rnorm(length(which(surv.days>250)), mean = 0, sd = 10)
survdata<- data.frame(surv.days, censor, surv.var)
rm(censor, surv.days, surv.var)
#using smoothHR package to adjust a model
variabledf<-dfmacox (time = "surv.days", status = "censor",
nl.predictor = c ("surv.var"),
smoother = "ns",
method = "AIC",
data = survdata)
coxmodel<- coxph(Surv(surv.days, censor) ~ ns(surv.var, variabledf$df[1]), data = survdata, x = TRUE)
c.smoothhr<-smoothHR (data = survdata, coxfit = coxmodel)
After that, I can plot the risk as a function of the survival variable
plot (c.smoothhr, predictor = "surv.var", conf.level = 0.95, ref.label = "", main = "", xlab = "surv.var")
I would like to generate this plot using the ggplot2 package, for storing and customization purposes; but I am simply clueless about how to proceed.