将geom_line和其他ggplot对象添加到autoplot.survfit

时间:2015-10-28 23:11:27

标签: r ggplot2

我正在尝试为survMisc生成的生存图添加额外的行,但是我无法使其工作 - 问题是最后一行。

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'))
  

eval(expr,envir,enclos)中的错误:object&#39; st&#39;找不到

我正在使用ggplot版本1.01和survMisc 0.4.6

1 个答案:

答案 0 :(得分:4)

问题在于,您添加的geom_line()图层默认会继承所有以前的美学映射 - 但您的新数据框不包含已映射的所有列。它很容易修复,你只需要停止继承:

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