[R] lattice question

o1bigtenor o1b|gtenor @end|ng |rom gm@||@com
Wed Aug 10 18:26:59 CEST 2022


On Wed, Aug 10, 2022 at 8:38 AM Deepayan Sarkar
<deepayan.sarkar using gmail.com> wrote:
>
> On Wed, Aug 10, 2022 at 4:53 PM Naresh Gurbuxani
> <naresh_gurbuxani using hotmail.com> wrote:
> >
> >
> > I want to merge two panels into one.  Is it possible to do this?
> >
> > Thanks,
> > Naresh
> >
> > library(lattice)
> > mydf <- data.frame(date = rep(seq.Date(as.Date("2022-08-01"), by = 1,
> > length.out = 10), 2), name = c(rep("Aa", 10), rep("Bb", 10)),
> > long = runif(20, 2, 10), short = runif(20, -10, 0))
> >
> > # This plots data in two panels.  I want all four lines in one panel.
> > xyplot(long + short ~ date, groups = name, data = mydf, type = c("l",
> > "g"))
>
> The "extended" formula API (with +) is really only meant as an
> alternative to reshape() for simple cases. In your case, you probably
> want something like
>
> mydf.long = reshape(mydf, direction = "long", varying = list(c("long",
> "short")), v.names = "X", timevar = "G", times = c("long", "short"))
>
> xyplot(X ~ date, groups = interaction(name, G), data = mydf.long, type
> = c("l", "g"))
>

(In the interest of learning- - ) Why?

Regards



More information about the R-help mailing list