Reputation: 1287
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
Upvotes: 2
Views: 2011
Reputation: 145755
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)
Upvotes: 5