


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















Some minimal examples showing the output of plots from the examples.
library("survMisc")
df0 <- data.frame(t1=c(0, 2, 4, 6, NA, NA, 12, 14), t2=c(NA, NA, 4, 6, 8, 10, 16, 18)) s1 <- Surv(df0$t1, df0$t2, type="interval2") plot(s1, l=2)
The ’autoplot’ function is a generic S3 method used by ’ggplot2’.
A more customized example follows. Note that we return only the element marked ’plot’ from the result (which is a list with two elements).
autoplot(t1, timeTicks="months", type="CI", jitter="all", legLabs=c("surgical", "percutaneous"), title="Time to infection following catheter placement \n by type of catheter, for dialysis patients",
titleSize=10, censSize=2)$plot
Here we assign the result in order to modify the y axis.
str(a1 <- autoplot(t1), max.level=1)
Here we also re-label the legend.
autoplot(b1, legOrd=c(3, 2, 1), legLabs=letters[1:3])
Now, let’s put the legend inside the plot itself.
a2 <- autoplot(b1)
a2$plot + ggplot2::theme(legend.position=c(0.75, 0.75)) a2$plot <- a2$plot + ggplot2::theme(legend.position=c(0.75, 0.75)) a
A number of options for plotting a line with just one group.
t2 <- ten(survfit(Surv(time=time, event=delta) ~ 1, data=kidney)) autoplot(t2, legLabs="")$plot autoplot(t2, legend=FALSE)
If the output of ’autoplot.ten’ is assigned, it can be modified in place. The list elements are ggplot2 objects which can be altered as usual.
t4 <- ten(survfit(Surv(time, delta) ~ type, data=kidney)) (a4 <- autoplot(t4, type="CI", alpha=0.8, survLineSize=2)$plot)
suppressMessages(a4 + list( ggplot2::scale_color_manual(values=c("red", "blue")), ggplot2::scale_fill_manual(values=c("red", "blue"))))
suppressMessages(a4 + ggplot2::scale_y_continuous(limits=c(0, 1)))
An example of the plots from a stratified model:
data("pbc", package="survival") t1 <- ten(Surv(time, status==2) ~ trt + strata(edema), data=pbc, abbNames=FALSE) suppressWarnings(str(a1 <- autoplot(t1), max.level=1))
a