2017-07-21 13 views

答えて

4

あなたのグラフはggplot2パッケージにgeom_segmentを使用して生成することができます。

df <- structure(list(Patient = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 
3L, 3L, 3L), .Label = c("Patient1", "Patient2", "Patient3"), class = "factor"), 
    Drug = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("Drug1", 
    "Drug2", "Drug3"), class = "factor"), StartDay = c(1L, 2L, 
    3L, 2L, 2L, 1L, 4L, 3L, 5L), StopDay = c(3L, 5L, 8L, 4L, 
    5L, 6L, 7L, 8L, 6L)), .Names = c("Patient", "Drug", "StartDay", 
"StopDay"), class = "data.frame", row.names = c(NA, -9L)) 

df$Drug <- factor(df$Drug, levels(df$Drug)[c(3,2,1)]) 

library(ggplot2) 
ggplot(data=df, aes(color=Drug))+ 
     geom_segment(aes(x=StartDay, xend=StopDay, y=Drug, yend=Drug),lwd=12)+ 
     facet_grid(Patient~.)+xlab("Days") 

enter image description here

関連する問題