Dear R-experts..

Thanks to Dennis and Deepayan for the valuable tips; I used a work-around to
indicate grouping variable inside a panel of a lattice. I am yet to get the
legends properly. Is "subscripts" needed for generating the legends inside a
lattice panel?

The work-around R code for the earlier provided dataset is included below..

mysymbols <- LETTERS[1:6]
barchart(Y1~factor(as.character(EP))|factor(Sno),
        data=ex1,
        groups=factor(DN),
        panel=function(x,y,groups,subscripts, ...)
{panel.superpose(x,y,groups=groups,subscripts,

panel.groups="panel.barchart",pch=mysymbols,distribute.type=T,col=rainbow(20))
        x1<- x; y1<- y; subs <- subscripts
        ltext(x1,y1,subscripts=subs,lab=ex1$DN)},
        layout = c(3, 3), aspect = 1,
        distribute.type=T,
        scales=list(rot=45,relation="free"),
        strip=strip.custom(list(strip.names=T,strip.levels=T)))

Your assistance is very highly appreciated.

Thanks
Santosh

On Wed, Feb 3, 2010 at 1:16 AM, Deepayan Sarkar
<deepayan.sarkar@gmail.com>wrote:

> On Wed, Feb 3, 2010 at 10:50 AM, Santosh <santosh2005@gmail.com> wrote:
> > Dear R-experts..
> >
> > I am trying to generate legend inside panels of lattice barplots..
> > Following is a sample dataset..
> >   Sno DN  EP Y1 Y2
> > 1    1 D1 A20 19 19
> > 2    1 D1 A50  8  9
> > 3    1 D1 A70  3  4
> > 4    2 D2 A20 22 22
> > 5    2 D2 A50 13 14
> > 6    2 D2 A70  6  7
> > 7    3 D2 A20 23 23
> > 8    3 D2 A50 12 13
> > 9    4 D1 A20 19 19
> > 10   4 D1 A50 10 10
> > 11   4 D1 A70  3  4
> > 12   5 D1 A20 28 28
> > 13   5 D1 A50 16 16
> > 14   5 D1 A70  7  7
> > 15   5 D3 A20 24 24
> > 16   5 D3 A50 14 14
> > 17   5 D3 A70  6  6
> > 18   6 D4 A20 15 15
> > 19   6 D4 A50  7  8
> > 20   6 D4 A70  3  3
> > 21   7 D5 A20 19 20
> > 22   7 D5 A50  5  6
> > 23   7 D5 A70  3  3
> > 24   8 D6 A20 26 26
> > 25   8 D6 A50 10 10
> > 26   9 D7 A20 30 30
> > 27   9 D7 A50 10  9
> > 28  10 D7 A20 21 22
> > 29  10 D7 A50 10 10
> > 30  10 D7 A70  4  4
> >
> > I am trying to generate barplot with legend inside each panel..where the
> > rectangular colors indicate the values for "DN". I have not been
> successful
> > in generating labels inside.. what am I missing?
>
> You should have
>
>             draw.key(list(
>                           rectangles=list(col=rainbow(6)),
>                           text=list(lab='DN')),
>                      draw = TRUE,
>                      vp = viewport(x = unit(0.5, "npc"), y = unit(0.5,
> "npc")))
>
> whereas you had
>
>             draw.key(list(
>                           rectangles=list(col=rainbow(6)),
>                           text=list(lab='DN'),
>                           draw = TRUE,
>                           vp = viewport(x = unit(0.5, "npc"), y =
> unit(0.5, "npc"))))
>
> -Deepayan
>
> >
> > barchart(Y1~factor(as.character(EP))|Sno,
> >        groups=DN,
> >        orgin=0,
> >        subscripts=T,
> >        panel = function(x,y,groups=groups, ...) {
> >          require(grid)
> >          panel.barchart(x,y,groups=groups,...)
> >          #panel.text(...)
> >          draw.key(list(
> >          rectangles=list(col=rainbow(6)),
> >          text=list(lab='DN'),
> >          draw = TRUE,
> >           vp = viewport(x = unit(0.5, "npc"), y = unit(0.5, "npc"))))},
> >        data=x1,
> >        distribute.type=T,
> >        layout=c(3,3),
> >        scales=list(rot=45,relation="free"))
> >
> > Thanks,
> > Santosh
>

	[[alternative HTML version deleted]]

