2
votes

I am trying to add extra lines to a survival plot generated by survMisc, however I can't get it to work - problem is the last line.

data(kidney, package="KMsurv")
s1 <- survfit(Surv(time, delta) ~ type, data=kidney)
p1<-autoplot(s1, type="fill", survLineSize=2)
d1=data.frame(x=seq(0,20,10),y=seq(0,1,.5))
p1$plot+geom_line(data=d1,aes_string(x='x',y='y'))

Error in eval(expr, envir, enclos) : object 'st' not found

I am using ggplot version 1.01 and survMisc 0.4.6

1
@Gregor updated question, what is your error?seanv507
Hmmm, nevermind I guess. I just tried on my laptop and it worked fine, but is still a problem on my work desktop.Gregor Thomas

1 Answers

5
votes

The problem is that the geom_line() layer you add inherits all previous aesthetic mappings by default - but your new data frame doesn't have all the columns that got mapped. It's easy to fix, you just need to stop the inheritance:

p1$plot +
    geom_line(data = d1,
              mapping = aes_string(x='x', y='y'),
              inherit.aes = F)