0

I am plotting survival curves for different strata with the following code

library(survival)
library(rms)
survplot(npsurv(formula =Surv(time, event)~group, data=df ), legend.pos = 'bottom')

On resulting graph line labels are not positioned well, as they overlap and run off the graph. How can I control positioning of labels? I am happy with just creating simple legend instead of putting labels next to line.

David C.
  • 1,854
  • 2
  • 17
  • 28
user1700890
  • 6,206
  • 15
  • 77
  • 160
  • 1
    We have no idea what your plot looks like because we can't run your code (we don't have your data). Be sure to include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample data. That will make it easier to help you. – MrFlick Feb 08 '17 at 23:07

1 Answers1

1

If you look at the code, near the end you see:

 if (labelc) 
        labcurve(curves, curve.labels, type = ltype, lty = lty, 
            col. = col, lwd = lwd, opts = label.curves)

And the label.curves argument should be a list as described in ?labcurve. I found that the plot produced by the first example on ?survplot would allow arbitrary adjustment with the use of the "locator" option to method:

survplot(f, age=mean(age), sex, conf.int=.95, 
         label.curves=list(method="locator"))

There are quite a few other options. The function putKey also is described on the same help page as ?labcurve if you would like to use a legend.

IRTFM
  • 251,731
  • 20
  • 347
  • 472