r - R:游泳图包注释
问题描述
我有一个使用 R 中的游泳图包构建的游泳图,并希望使用来自 data.frame 的另一个变量的因子/文本来注释每个条形图,该变量属于相应的 id/患者。
我无法共享数据,但这是我目前正在处理的代码,最后一行是我未能注释(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")
编辑:无法重命名患者变量/刻度线。id 必须是可见的,只能添加注释。
解决方案
总结一下要点:
- 在最后一行,
geom_text
使用函数中的x
andy
参数aes()
- 标准中通常不引用变量名
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")
推荐阅读
- java - 棋子JavaFX周围的国际象棋边框
- jquery - jQuery mouseover 和 mouseleave - 当我多次将鼠标悬停在一个元素上时,效果将播放不止一次
- mongodb - MongoDB:为两个不同的用户找到相同的条目?
- python - 并行 Python-C++ 程序冻结(内存?)
- angular - ng:键或 ID 为“http://json-schema.org/draft-06/schema”的模式已存在
- php - 未定义索引:执行 IF 和 Elseif
- tensorflow - 关于下载特定tensorflow版本的url链接
- python - 如何在 setup.py (pySFML) 中指定 C++ 头文件和库文件夹?
- api - Tumblr API 返回错误代码 1016
- ruby-on-rails - 在 Ruby on rails 应用程序中启用 https ssl