0

Good day,

I am using xyplot() to create a spaghetti plot... for each subject_identifier it plots the score of Y over time.

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

An event happens for each subject_identifier at some specified time, event_time. How can I make a tick or a dot on each line at event_time for each individual?

Thanks

Zacarias
  • 25
  • 3
  • 1
    You should post a sample data set. It's not clear how your event_time data is being stored. – IRTFM Jun 13 '12 at 21:06

1 Answers1

1

If the event_times are a vector: event_times <- c(5,3,6,8) and you expect the groups to line up in order with those indices then you can use groups as an index into event_times which will then be indices for x and y in the panel arguments:

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'))

So the first group gets ticked at time=5, the second at time=3 , and so on. Need to offset by (group-1)*10 although there may be cleaner approaches with panel.superpose. Other options for ticks are of course possible but you have been rather vague in your problem presentation.

enter image description here

IRTFM
  • 258,963
  • 21
  • 364
  • 487