R: swimplot 包注释

R: swimplot package annotate

我有一个用 R 中的 swimplot 包构建的 swimmerplot,我想用属于各自 id/patient 的 data.frame 的另一个变量中的 factor/text 注释每个条。

我无法共享数据,但这是我目前正在处理的一段代码,最后一行是我未能注释(Best.response.1 是相应文本变量的名称). “id”是患者变量,“daysuntildeath”是时间变量。

plot3 <- swimmer_plot(df=data ,id='id',end='daysuntildeath',
                      width=.85, name_fill="Drug.1", id_order="Drug.1") +
    scale_fill_manual(name="Drug.1", values = c("coral1", "lavenderblush4", "maroon4","springgreen3" , "springgreen4", "yellowgreen", "dodgerblue2"))
##################### adding symbols for censoring #############################
### censoring
plot4 <- plot3 + swimmer_points(df_points=
                      data,id='id',time='daysuntildeath',name_shape =
                      'event',size=2.5,fill='white',col='black')
p4_new = plot4 + scale_y_discrete(expand = c(0.15,0)) + labs(y = "Days until death") +
  geom_text(x = "id", y = "daysuntildeath", aes(label = "Best.response.1"), vjust = -0.2, colour = "black")

编辑:无法重命名患者 variables/tick 标记。 id 必须是可见的,只能添加注释。

总结要点:

  • 在最后一行中,geom_textaes() 函数中使用 xy 参数
  • 标准中通常不引用变量名 ggplot2

所以最后一行代码应该是:

p4_new = plot4 + scale_y_discrete(expand = c(0.15,0)) + 
   labs(y = "Days until death") +
   geom_text(aes(x = id, y = daysuntildeath, label = Best.response.1), 
             vjust = -0.2, colour = "black")