Creating the survival plot

We’ve mentioned that healthvis makes some nice interactive figures using just one line of R code, but we haven’t showed an example yet. Remember the grouped survival comparison from the announcement post? This is what you would do in R to create it:

# Load the survival library
library(survival)
# Convert trt and prior to factors so they are treated as such by the plotting function
veteran$trt <- as.factor(veteran$trt)
veteran$prior <- as.factor(veteran$prior)
# Run a cox proportional hazards regression
cobj <- coxph(Surv(time, status)~trt+age+celltype+prior, data=veteran)
# Here's the plotting command!
survivalVis(cobj, data=veteran, plot.title="Veteran Survival Data", group="trt", group.names=c("Treatment", "No Treatment"), line.col=c("#E495A5","#39BEB1"))

Above, we fit a proportional hazards model that takes into account a subject’s treatment status, disease cell type, and whether or not they have had prior therapy. In the “survivalVis” call, we simply pass the model fit object, the data set (“veteran” data from the “survival” R package), a plot title, the model covariate on which we want to group (here, treatment or “trt”), and group names and colors.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s