Search code examples
rlattice

xyplot panels in the wrong order


I have a problem plotting my xyplot. My table is ordered by day but I can't get the right order from Tuesday to Sunday. I have tried to add as.table=T but it's not working. Any tips ?

    data <- read.csv("exemple.csv", header=TRUE, sep=";")
    attach(data)
    xyplot(Nos~Period|Day,layout=c(6,1),type="o")
    detach(data)

Moreover, I would like to add a second "line" of panels for the column Cas. I know if I want to add on the same panel I just have to write :

xyplot(Nos+Cas~Period|Day,layout=c(6,1),type="o")

Here is my data:

     Day    Period  Cas Nos Bis
1   Tuesday     1   131 14  176
2   Tuesday     2   203 107 138
3   Tuesday     3   118 163 131
4   Wednesday   1   143 80  165
5   Wednesday   2   232 151 158
6   Wednesday   3   130 101 143
7   Thursday    1   203 151 275
8   Thursday    2   165 108 134
9   Thursday    3   120 90  109
10  Friday      1   99  60  128
11  Friday      2   367 232 155
12  Friday      3   216 248 154
13  Saturday    1   158 134 184
14  Saturday    2   295 187 175
15  Saturday    3   210 310 145
16  Sunday      1   115 73  114
17  Sunday      2   232 124 160
18  Sunday      3   211 133 144

Thank you !

Lisa


Solution

  • you can try this code without creating factors and reordering levels

    xyplot(Nos~Period|I(Day),layout=c(6,1),type="o", index.cond=list(c(5,4,6, 1:3)))
    

    index.cond reorder the plot as you wish