在R中创建时间过程图

我想为一小群人(约25名研究参与者)创建一个时间表。每个参与者都有一条从T0到T1的时间线,然后某些事件将以符号表示并叠加在图形上。我从这里引用的一篇出色的柳叶刀论文中附上了一个时间课程的图形示例。

Lescure FX,Bouadma L,Nguyen D等。欧洲首批COVID-19病例的临床和病毒学数据:一个病例系列[于印刷版在线发布,2020年3月27日] [已发表的校正发表在Lancet Infect Dis中。 2020年5月19日;:]。柳叶刀感染病。 2020; S1473-3099(20)30200-0。

[![在此处输入图片描述] [1]] [1]

enter image description here

我创建了一些示例数据。

structure(list(ID = structure(1:5, .Label = c("a", "b", "c", 
"d", "e"), class = "factor"), T0..start. = structure(c(3L, 1L, 
2L, 4L, 5L), .Label = c("4/14/2013", "5/2/2017", "6/5/2012", 
"6/8/2018", "9/9/2019"), class = "factor"), T0.type = structure(c(4L, 
3L, 1L, 2L, 1L), .Label = c("A", "A,S", "O", "S"), class = "factor"), 
e1 = structure(c(3L, 1L, 2L, 4L, NA), .Label = c("5/1/2014", 
"6/2/2017", "7/3/2017", "8/7/2018"), class = "factor"), e1.type = structure(c(2L, 
3L, 3L, 1L, NA), .Label = c("A", "A, O", "O"), class = "factor"), 
e2 = structure(c(NA, 1L, NA, NA, NA), .Label = "7/7/2016", class = "factor"), 
e2.type = structure(c(NA, 1L, NA, NA, NA), .Label = "A,S", class = "factor"), 
A1 = structure(c(3L, 2L, 1L, 4L, 5L), .Label = c("5/5/2017", 
"5/6/2014", "6/20/2012", "7/7/2018", "9/20/201"), class = "factor"), 
A1.type = structure(c(1L, 3L, 4L, 2L, 4L), .Label = c("M", 
"N", "N, M", "N,M"), class = "factor"), A2 = structure(c(2L, 
NA, NA, 1L, NA), .Label = c("7/23/2018", "7/7/2017"), class = "factor"), 
A2.type = structure(c(2L, NA, NA, 1L, NA), .Label = c("M", 
"N"), class = "factor"), R..start. = structure(c(4L, 3L, 
2L, 5L, 1L), .Label = c("10/19/2019", "6/7/2017", "7/30/2016", 
"8/14/2012", "9/9/2018"), class = "factor"), R..end. = structure(c(3L, 
4L, 2L, 5L, 1L), .Label = c("12/19/2019", "6/7/2019", "8/21/2013", 
"8/9/2017", "9/9/2019"), class = "factor"), R.type = structure(c(2L, 
3L, 2L, 2L, 1L), .Label = c("A", "C", "M"), class = "factor"), 
T1..end. = structure(c(4L, 2L, 3L, 5L, 1L), .Label = c("12/30/2019", 
"3/3/2019", "6/7/2019", "8/4/2019", "9/9/2019"), class = "factor"), 
time = c(2616L, 2149L, 766L, 458L, 112L)), class = "data.frame", row.names = c(NA, 
-5L))

对于带有“类型”的列,我想放置一个符号(点,正方形,星形等)。对于R的开始和结束,我想放置一条平行线(与时间线平行)。

我从按时间绘制的每个ID的水平条形图开始。我不确定如何在正确的时间点沿每条线绘制符号。

ggplot(data=example, aes(x=ID, y=time, fill = ID)) +
  geom_bar(stat="identity")+
  scale_colour_gradient2()+
  coord_flip() +
  ylim(0, 3000)  +
  theme_classic()
评论