celestialgod

trend plot in lattice

Mar 14th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.52 KB | None | 0 0
  1. library(lattice)
  2. library(data.table)
  3. library(pipeR)
  4.  
  5. N <- 1093L
  6. DT <- data.table(time = Sys.time() + sample.int(86400L, N),
  7.                  value = rnorm(N))
  8.  
  9. DT[ , idx := rank(time) %>>% match(sort(unique(.)))]
  10. lenXTick <- 20L
  11. xAt <- seq(1, nrow(DT), length.out = lenXTick)
  12. xTickLabel <- DT[idx %in% pmax(1L, floor(xAt)), .(time)] %>>% format("%Y-%m-%d")
  13. xyplot(value ~ idx, DT, scales = list(x = list(at = xAt, labels = xTickLabel,
  14.                                                tick.number = lenXTick, rot = 90)))
Advertisement
Add Comment
Please, Sign In to add comment