Ryp中的xyplot(),意大利面条图,如何为每个人在某一点勾选

时间:2012-06-13 20:51:42

标签: r plot lattice

美好的一天,

我正在使用xyplot()来创建意大利面条图......对于每个subject_identifier,它会绘制Y随时间的分数。

xyplot(Y~time,groups=subject_identifier,data=c,type=c('l'))

在某个指定时间event_time,每个subject_identifier都会发生一个事件。如何在每个人的event_time上为每一行写一个勾号或一个点?

由于

1 个答案:

答案 0 :(得分:1)

如果event_times是一个向量:event_times <- c(5,3,6,8)并且你希望groups按顺序排列这些索引,那么你可以使用组作为event_times的索引,这将是x和x的索引y在面板参数中:

xyplot(Y~time,groups=subject_identifier,data=cdat,
              panel=function(x,y,groups,...){
                panel.xyplot(x,y,groups=groups,...)
                panel.segments(x0=x[(grp-1)*10+event_times[grp]],
                               x1=x[(grp-1)*10+event_times[grp]], 
                               y0=y[(grp-1)*10+event_times[grp]]-.2,
                             y1=y[(grp-1)*10+event_times[grp]]+.2, groups=groups,...)},
       type=c('l'))

因此第一组在时间= 5时被勾选,第二组在时间= 3时被勾选,依此类推。需要偏移(group-1)*10,尽管panel.superpose可能有更简洁的方法。刻度的其他选项当然是可能的,但你在问题陈述中却相当模糊。

enter image description here

相关问题