3

I am making a failure plot and would like to have the at risk table show up above the x-axis line but below the y=0 point. This is because for this plot most of the data is near the bottom so it overlaps too much (right now I am putting the table at the top of the graph). The following will fit the curve in this white area - Specifically the ylim and y.n.risk options (the latter sets the bottom position of the at risk table). However, I do not want the y-axis to show a label for -0.2 because obviously that does not make sense for survival. Is there a way to hide this value?

survplot(cm1b_surv, fun=function(y)(1-y), lty=c(1,2,3),xlim=c(0,30),ylim=c(-0.2,0.8),time.inc=5,
     conf='none', n.risk=TRUE, adj.n.risk=0.5, cex.n.risk=0.65, levels.only=TRUE, y.n.risk=-0.2,
     xlab='Time from Donation to Event (Years)',
     ylab='Probability of Diagnosis')

Ironically enough, SAS (which is what my experience is in for 12 years) does let you do that, and I would like a plot to mimic that specific aspect. See figure 8 in this pdf:

https://support.sas.com/resources/papers/proceedings13/427-2013.pdf

edit: Here's a reproducible example. Sorry but I haven't figured out all the formatting tricks yet. This code will generate a sample cumulative probability curve with the at risk table in the negative portion of the y-axis. I'd like to hide the -0.2 value and the tick mark if possible from the y-axis.

library(rms)
library(survival) 
yrs_sample<-c(1:100) 
Prob <- c(0.9, 0.3, 0.6, 0.8, 0.23, 0.45, 0.1, 0.3, 0.5, 0.03) 
niter<- 100 
randomSample<-rbinom(niter,1,prob=rep(Prob,niter)) 
surv_sample<-data.frame(yrs_sample,randomSample) 

sample_surv<-npsurv(Surv(yrs_sample,randomSample)~1,data=sur‌​v_sample) 

survplot(sample_surv, fun=function(y)(1-y),lty=c(1,2,3),xlim=c(0,30),ylim=c(-0.2,0.8),time.inc=5, conf='none', n.risk=TRUE, adj.n.risk=0.5, cex.n.risk=0.65, levels.only=TRUE, y.n.risk=-0.2)

Thanks!

Scott

Scott Jackson
  • 411
  • 1
  • 4
  • 11
  • It's easier to help you if you provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data so we can run the code to see what is being produced and can try possible solutions. – MrFlick Mar 22 '17 at 15:16
  • You should edit your question to include this information. Don't put it in the comments. – MrFlick Mar 22 '17 at 15:46
  • 1
    It seems that the plot function doesnt take `yaxt` or `axes` arguments (you could look at the code to see why). So you could do a bit of a hack by suppressing the yaxis globally, doing the plot, then add in the axis manually. So `par(yaxt="n") ; Now do the survplot ; par(yaxt="s") ; axis(2, at=seq(0, 0.8, 0.2))` . Tweak the `at` and `labels` argument to suit. – user20650 Mar 22 '17 at 19:42
  • 1
    That works, thank you. I had done the first part but hadn't thought of simply reenabling yaxt after (I thought par would only go before the plot for some reason). – Scott Jackson Mar 22 '17 at 20:46

0 Answers0