[R] lattice shingle plot axis annotation
Deepayan Sarkar
deepayan.sarkar at gmail.com
Mon Aug 3 20:06:22 CEST 2009
On Thu, Jul 30, 2009 at 12:43 AM, Armin Goralczyk<agoralczyk at gmail.com> wrote:
> Hello (R-)Experts
>
> I hope someone can help with this problem concerning axis annotation
> of a lattice shingle plot. I want a plot with three shingles to
> display some laboratory value over time. In the first panel over the
> first few days, then in the next panel some months, and in the last
> panel some years. In the following minimal example the axis annotation
> will be in days, but I'd like to have days in the fisrt panel, months
> in the second panel and years in the third panel. Is it possible?
>
> pod <- seq(1, 5000, 5)
> test <- data.frame(pod=pod,
> val=rep(c(1,2,4,8), length=length(pod)),
> g=rep(c('A', 'B'), length=length(pod)))
> shingle.pod <- shingle(test$pod, intervals = rbind(c(0, 20), c(20, 180),
> c(220, 6000)))
> test.plot <- xyplot(val ~ pod | shingle.pod,
> data = test,
> groups = test$g,
> scales = list(x = "free",
> y = list(relation = "same", log = 2)),
> between = list(x = 0.5),
> panel = function(x, y, ...) {
> panel.grid(h = -1, v = -1, lwd = 1)
> panel.superpose(x, y, ...)
> },
> type = c('b')
> )
> plot(test.plot)
>
> (this plot doesn't look good, I know, it's just and example)
If your panels do not overlap, it may be simplest to rescale your data
beforehand:
rescale <- function (x)
{
ans <- x
mid <- x > 20 & x < 180
ans[mid] <- ans[mid]/30
hi <- x >= 180
ans[hi] <- ans[hi]/365
ans
}
test.plot <- xyplot(val ~ rescale(pod) | shingle.pod,
data = test,
groups = test$g,
scales = list(x = "free",
etc.
-Deepayan
More information about the R-help
mailing list