如何在ggplot中相互绘制两个时间序列?

时间:2016-08-15 14:23:33

标签: r ggplot2

我有以下结构中的数据

test <- data.frame(
  ID=c("1","2","3"), 
  name=c("A","A", "C"), 
  persons_g1_0min=c(1,2,3), 
  persons_g1_10min=c(4,5,6),
  persons_g1_30min=c(7,8,9),
  persons_g2_0min=c(10,11,12), 
  persons_g2_10min=c(13,14,15),
  persons_g2_30min=c(16,17,18))

ID    name    g1_0min      g1_10min   g1_30min    g2_0min    g2_10min    g2_30min
1     A       1            4          7           10         13          16
2     A       2            5          8           11         14          17
3     C       3            6          9           12         15          18

我想知道0的时间点1030g101030 g2。正常情节我可以用

做到
for (ID in test$ID){
  part <- test[test$ID==ID,]
  plot(c(part$persons_g1_0min, part$persons_g1_10min, part$persons_g1_30min),
       c(part$persons_g2_0min, part$persons_g2_10min, part$persons_g2_30min))
}

但我怎样才能用ggplot做到这一点?

0 个答案:

没有答案