user3922546
user3922546

Reputation: 187

Panel plot using lattice package in R

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.

Upvotes: 1

Views: 1771

Answers (1)

tkngoutham
tkngoutham

Reputation: 11

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

Upvotes: 1

Related Questions