How do you reverse lattice panel draw order for timeseries data?

I have signal timeseries data that I'd like to split into multiple lattice panels, arranged in a single column, to make variation easier to see. Unfortunately, the code I'm using draws panels in reverse chronological order (newer data are in the top panel instead of older).

How can I reverse the panel draw order?

I tried converting the Timestamp field to a factor and reversing the levels, as suggested in similar posts, but that hasn't improved my situation, which I suspect is related to using posix times; panel draw order remains unaffected and x-axis ticks/labels are reformatted.

#Example

library(lattice)

data <- data.frame(
  Timestamp = seq(
    from = as.POSIXct("2016-01-01 00:00:00 PST"),
    length.out = 1000,
    by = "hours"
  ),
  Signal = rnorm(1000)
)

Timeline <- equal.count(data$Timestamp, number = 4, overlap = 0)

xyplot(
  Signal ~ Timestamp | Timeline,
  data,
  grid = TRUE,
  auto.key = TRUE,
  scales = list(relation = "free"),
  layout = c(1, 4),
  xlab = "Timestamp",
  ylab = "Signal Value",
  main = "My Funky Lattice Plot"
)

Per the package author, Deepayan Sarkar, adding as.table = TRUE to the xyplot function changes the default bottom-to-top ordering to top-to-bottom.

My lattice plot panels render chronologically without issue now.

Thank you, Deepayan!

#solution
library(lattice)

data <- data.frame(
  Timestamp = seq(
    from = as.POSIXct("2016-01-01 00:00:00 PST"),
    length.out = 1000,
    by = "hours"
  ),
  Signal = rnorm(1000)
)

Timeline <- equal.count(data$Timestamp, number = 4, overlap = 0)

xyplot(
  Signal ~ Timestamp | Timeline,
  data,
  grid = TRUE,
  auto.key = TRUE,
  scales = list(relation = "free"),
  layout = c(1, 4),
  as.table = TRUE, #add this line to change panel order
  xlab = "Timestamp",
  ylab = "Signal Value",
  main = "My Defunked Lattice Plot"
)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.