Survival Plot in R 2.10.0
On Nov 6, 2009, at 1:16 PM, mah wrote:
I would like to produce a complimentary log-log survival plot with only the points appearing on the graph. I am using the code below, taken from the plot.survfit page of help for the the survival package (version 2.35-7). I am running in R 2.10.0 on Windows XP, and the list of packages following the error is loaded. Is there some specific 'type= ' syntax, or an additional parameter that I must specify?
leukemia.surv <- survfit(Surv(time, status) ~ x, data = aml) plot(leukemia.surv, lty = 2:3) ## works fine plot(leukemia.surv, lty = 2:3, fun="cloglog") ## works fine plot(leukemia.surv, type="p") ## generates error below:
Error in plot.default(tempx, tempy * yscale, type = "n", log = logax, : formal argument "type" matched by multiple actual arguments
search()
[1] ".GlobalEnv" "package:survival" "package:splines" [4] "package:stats" "package:graphics" "package:grDevices" [7] "package:utils" "package:datasets" "package:methods" [10] "Autoloads" "package:base" I can get a plot of points using plot(log(leukemia.surv$time),log(-log (leukemia.surv$surv)), type="p"), but then I lose the functionality of grid(). Ulimately what I want to do is overlay these plotted points with lines generated by various parametric survival models (dist=weibull, lognormal, etc). All help is appreciated. Thanks in advance!
plot.survfit() does not support a 'type' argument. Internally in plot.survfit(), plot() is called explicitly with 'type = 'n' along with a '...' argument. When you try to call plot.survfit() with an explicit "type = 'p'" argument, it is passed to plot() as one of the '...' arguments. This means that internally plot() is called with two 'type' arguments, hence the error you get above. It would be like calling: > plot(1, 1, type = 'n', type = 'p') Error in plot.default(1, 1, type = "n", type = "p") : formal argument "type" matched by multiple actual arguments I have not used it in this particular manner, but you might want to look at using ?lines.survfit to add the survival model lines on an existing plot. An alternative to grid() is just to use abline(), which can draw horizontal and vertical lines at given x and y values and is what is used internally in grid(). See ?abline and also review ?par and take note of 'lty' and 'lwd', which define the line types and widths. Although, I was able to use grid() after your last plot() call above drawing points, so perhaps I am missing something: plot(log(leukemia.surv$time), log(-log(leukemia.surv$surv)), type = "p") grid() HTH, Marc Schwartz