1

I would like to make an xyplot using lattice with 2 panels one over the other corresponding to a variable(date) having 2 levels(Weekday and Weekend). My dataframe looks like this:

 interval    date      steps
1        0 Weekday 2.25115556
2        5 Weekday 0.44528000
3       10 Weekday 0.17316889
4       15 Weekday 0.19789778
5       20 Weekday 0.09895556
6       25 Weekday 1.59035111
 .
 .
 .  
289        0 Weekend   0.21462500
290        5 Weekend   0.04245000
291       10 Weekend   0.01651250
292       15 Weekend   0.01886250
293       20 Weekend   0.00943750
294       25 Weekend   3.51178750

I used the following code:

xyplot(steps ~ interval| levels(activity.week.mean$date), 
           data = activity.week.mean,
           type = "l",
           xlab = "Interval",
           ylab = "Number of steps",
           layout=c(1,2))

What happens is that I get 2 panels with both having the distribution of Weekend and Weekday but I need one for each. Thanks in advance.

user3922546
  • 187
  • 1
  • 6
  • 16
  • 2
    Have you tried `steps~interval|date`? It nice that you have the data included, but in general it is more helpful for someone trying to use these data when you use the output of `dput(activity.week.mean)` – Dieter Menne Sep 06 '14 at 17:10
  • Perfect! I actually tried this earlier but that was before I changed the date to a factor variable with 2 levels which messed up the results. – user3922546 Sep 06 '14 at 17:33

1 Answers1

1

Instead of |levels(date) you should be using |factor(date) or just |date

xyplot(steps~interval|factor(date),
       type='l',layout=c(1,2),
       xlab='Interval',ylab='Number of Steps')
BenBarnes
  • 19,114
  • 6
  • 56
  • 74
tkngoutham
  • 11
  • 1