Skip to content
Prev 392437 / 398502 Next

lattice question

This is the solution I was looking for.  Thanks to Deepayan and Bert for sticking with me.

Naresh

Sent from my iPhone
On Aug 12, 2022, at 8:02 AM, Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote:
?
On Thu, Aug 11, 2022 at 9:03 PM Naresh Gurbuxani <naresh_gurbuxani at hotmail.com<mailto:naresh_gurbuxani at hotmail.com>> wrote:
Bert,

Thanks for providing this solution.  It produces the desired graph.

To see how I want to distinguish groups, you should look at original data (mydf).  There are two groups (Aa and Bb), each with two time series (long and short).  Long is always positive.  Short is always negative.  Therefore, there is no need to distinguish between long and short.  I only need to distinguish between Aa and Bb.

I agree that more than six lines in the graph will make it cluttered.  In fact the above exercise is to avoid clutter in the key.  No need to show Aa.long and Aa.short, because long and short are obvious.

In that case, this alternative approach may be conceptually simpler:

library(latticeExtra)

r <- with(mydf, extendrange(range(long, short)))

plong <- xyplot(long ~ date, groups = name, data = mydf,
                type = "l", grid = TRUE,
                ylim = r)

pshort <- xyplot(short ~ date, groups = name, data = mydf, type = "l")

plong + pshort

The first plot here is the "main" one, so you need to make sure that its 'ylim' is big enough for all the data.

-Deepayan



Thanks,
Naresh

Sent from my iPhone