[R] Graph Order in xyplot

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Jul 2 00:34:30 CEST 2008


On 7/1/08, Sam Albers <tonightsthenight at gmail.com> wrote:
> I have constructed a Trellis style xyplot.
>
>  lengthf <- factor(length)
>  xyplot(SLI$velocity ~ SLI$width | SLI$lengthf, layout = c(2,7), xlab =
>  "Width (cm)", ylab = "Velocity (m/s^2)", col = "black")

As an aside, the recommended incantation is

xyplot(velocity ~ width | lengthf, data = SLI, <etc.>)

>  This produces a lovely little plot. However, the grouping factor(lengthf)
>  isn't in the right order. My values range from 2-28 and the 2 graph on the
>  bottom left and the graphs continue sequentially left to right to the top of
>  the page. I would like to have the 2 at the top and have the graphs shown in
>  descending order (i.e. have the entire graph read like a book)
>
>  I tried the following but it didn't seem to work.
>
>  lengthd <-sort(SLI$length, decreasing =TRUE)
>  lengthdf <- factor(SLI$lengthd)

This wouldn't do anything new unless you also specify a 'levels'
argument in your call to factor().

>  Then I plotted the graph again:
>  xyplot(SLI$velocity ~ SLI$width | SLI$lengthdf, layout = c(2,7), xlab =
>  "Width (cm)", ylab = "Velocity (m/s^2)", col = "black")
>
>  This simply gave me the same graph and now I am a little lost. Is there an
>  easier way to do this? Do I have to rearrange my data or can this be changed
>  around using the original xyplot command line.

Perhaps you are looking for

xyplot(velocity ~ width | lengthf, data = SLI,
       as.table = TRUE, [...])

-Deepayan



More information about the R-help mailing list