Re: [R] Adding different output to different lattice panels

2007-06-28 Thread Deepayan Sarkar
On 6/28/07, Alexandre Salvador <[EMAIL PROTECTED]> wrote:
> Selon [EMAIL PROTECTED]:
>
> > On 6/28/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > > I would like to add a reference line to lattice graphs, with the reference
> > > line
> > > being different according to the factor level.
> > >
> > > Example : Draw 3 dotplots for "a","b" and "c" factors, and then add an
> > > horizontal line at y=10 for panel "a", y=8 for panel "b" and y=6 for panel
> > > "4"
> > >
> > > I tried the code below, but this draw all three reference lines for each
> > > panel.
> > > How do I index the current panel to chose the right reference vector value
> > ?
> > >
> > >
> >
> dat<-data.frame(id=rep(c("a","b","c"),4),val=1:12,quand=rep(c("t1","t2","t3","t4"),each=3))
> > > ref<-c(10,8,6)
> > > plot.new()
> > > datplot<-dotplot(val~quand|id,data=dat,panel=function(...){
> > > panel.dotplot(...)
> > > panel.abline(h=ref)
> > > })
> > > print(datplot)
> >
> > dotplot(val~quand|id,data=dat,panel=function(...){
> > panel.dotplot(...)
> > panel.abline(h = ref[packet.number()])
> > })
> >
> > (Things are more complicated if you have more than one conditioning
> > variable.)
> >
> > -Deepayan
> >
>
> I tried you solution, but the following error appears when I print(datplot):
>
>Erreur dans as.numeric(h) : impossible de trouver la fonction 
> "packet.number"
>
> I have lattice and grid libraries loaded. The exact code I use is
> datplot<-dotplot(val~quand|id,data=dat,panel=function(...){
> panel.dotplot(...)
> panel.abline(h=ref[packet.number()])
> })
> print(datplot)
> What do I do wrong ?

You are using a very old version of R (or at least old enough that the
packet.number number didn't exist). You haven't told us what version
you are using.

I would encourage you to upgrade, but this might work for now:

dotplot(val~quand|id,data=dat,
panel=function(..., panel.number){
panel.dotplot(...)
panel.abline(h = ref[panel.number])
})

> Note : I usually need to use the indirect datplot<-dotplot(...  and then
> print(datplot) when I store my code in a file and use it through
> source("myfile.R"). The direct dotplot(... does not open a device whereas it
> does if I type directly dotplot(... at the R command line...
> Is this normal ?

Yes, and a FAQ:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

-Deepayan

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adding different output to different lattice panels

2007-06-28 Thread Alexandre Salvador
Selon Deepayan Sarkar <[EMAIL PROTECTED]>:

> On 6/28/07, Alexandre Salvador <[EMAIL PROTECTED]> wrote:
> > Selon [EMAIL PROTECTED]:
> >
> > > On 6/28/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > > > I would like to add a reference line to lattice graphs, with the
> reference
> > > > line
> > > > being different according to the factor level.
> > > >
> > > > Example : Draw 3 dotplots for "a","b" and "c" factors, and then add an
> > > > horizontal line at y=10 for panel "a", y=8 for panel "b" and y=6 for
> panel
> > > > "4"
> > > >
> > > > I tried the code below, but this draw all three reference lines for
> each
> > > > panel.
> > > > How do I index the current panel to chose the right reference vector
> value
> > > ?
> > > >
> > > >
> > >
> >
>
dat<-data.frame(id=rep(c("a","b","c"),4),val=1:12,quand=rep(c("t1","t2","t3","t4"),each=3))
> > > > ref<-c(10,8,6)
> > > > plot.new()
> > > > datplot<-dotplot(val~quand|id,data=dat,panel=function(...){
> > > > panel.dotplot(...)
> > > > panel.abline(h=ref)
> > > > })
> > > > print(datplot)
> > >
> > > dotplot(val~quand|id,data=dat,panel=function(...){
> > > panel.dotplot(...)
> > > panel.abline(h = ref[packet.number()])
> > > })
> > >
> > > (Things are more complicated if you have more than one conditioning
> > > variable.)
> > >
> > > -Deepayan
> > >
> >
> > I tried you solution, but the following error appears when I
> print(datplot):
> >
> >Erreur dans as.numeric(h) : impossible de trouver la fonction
> "packet.number"
> >
> > I have lattice and grid libraries loaded. The exact code I use is
> > datplot<-dotplot(val~quand|id,data=dat,panel=function(...){
> > panel.dotplot(...)
> > panel.abline(h=ref[packet.number()])
> > })
> > print(datplot)
> > What do I do wrong ?
>
> You are using a very old version of R (or at least old enough that the
> packet.number number didn't exist). You haven't told us what version
> you are using.
>
> I would encourage you to upgrade, but this might work for now:
>
> dotplot(val~quand|id,data=dat,
> panel=function(..., panel.number){
> panel.dotplot(...)
> panel.abline(h = ref[panel.number])
> })
>
> > Note : I usually need to use the indirect datplot<-dotplot(...  and then
> > print(datplot) when I store my code in a file and use it through
> > source("myfile.R"). The direct dotplot(... does not open a device whereas
> it
> > does if I type directly dotplot(... at the R command line...
> > Is this normal ?
>
> Yes, and a FAQ:
>
>
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f
>
> -Deepayan
>
Works all right,
I use Version 2.3.1 (2006-06-01)
I'll upgrade to the newer versions...
Thanks very much,
Cheers

--
Alexandre Salvador
Tel: +33(0)6.8214.7733

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adding different output to different lattice panels

2007-06-28 Thread Alexandre Salvador
Selon [EMAIL PROTECTED]:

> On 6/28/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > I would like to add a reference line to lattice graphs, with the reference
> > line
> > being different according to the factor level.
> >
> > Example : Draw 3 dotplots for "a","b" and "c" factors, and then add an
> > horizontal line at y=10 for panel "a", y=8 for panel "b" and y=6 for panel
> > "4"
> >
> > I tried the code below, but this draw all three reference lines for each
> > panel.
> > How do I index the current panel to chose the right reference vector value
> ?
> >
> >
>
dat<-data.frame(id=rep(c("a","b","c"),4),val=1:12,quand=rep(c("t1","t2","t3","t4"),each=3))
> > ref<-c(10,8,6)
> > plot.new()
> > datplot<-dotplot(val~quand|id,data=dat,panel=function(...){
> > panel.dotplot(...)
> > panel.abline(h=ref)
> > })
> > print(datplot)
>
> dotplot(val~quand|id,data=dat,panel=function(...){
> panel.dotplot(...)
> panel.abline(h = ref[packet.number()])
> })
>
> (Things are more complicated if you have more than one conditioning
> variable.)
>
> -Deepayan
>

I tried you solution, but the following error appears when I print(datplot):

   Erreur dans as.numeric(h) : impossible de trouver la fonction "packet.number"

I have lattice and grid libraries loaded. The exact code I use is
datplot<-dotplot(val~quand|id,data=dat,panel=function(...){
panel.dotplot(...)
panel.abline(h=ref[packet.number()])
})
print(datplot)
What do I do wrong ?

Note : I usually need to use the indirect datplot<-dotplot(...  and then
print(datplot) when I store my code in a file and use it through
source("myfile.R"). The direct dotplot(... does not open a device whereas it
does if I type directly dotplot(... at the R command line...
Is this normal ?

--
Alexandre Salvador
Tel: +33(0)6.8214.7733

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adding different output to different lattice panels

2007-06-28 Thread deepayan . sarkar
On 6/28/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I would like to add a reference line to lattice graphs, with the reference
> line
> being different according to the factor level.
>
> Example : Draw 3 dotplots for "a","b" and "c" factors, and then add an
> horizontal line at y=10 for panel "a", y=8 for panel "b" and y=6 for panel
> "4"
>
> I tried the code below, but this draw all three reference lines for each
> panel.
> How do I index the current panel to chose the right reference vector value ?
>
> dat<-data.frame(id=rep(c("a","b","c"),4),val=1:12,quand=rep(c("t1","t2","t3","t4"),each=3))
> ref<-c(10,8,6)
> plot.new()
> datplot<-dotplot(val~quand|id,data=dat,panel=function(...){
> panel.dotplot(...)
> panel.abline(h=ref)
> })
> print(datplot)

dotplot(val~quand|id,data=dat,panel=function(...){
panel.dotplot(...)
panel.abline(h = ref[packet.number()])
})

(Things are more complicated if you have more than one conditioning variable.)

-Deepayan

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adding different output to different lattice panels

2007-06-28 Thread hadley wickham
On 6/28/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I would like to add a reference line to lattice graphs, with the reference 
> line
> being different according to the factor level.
>
> Example : Draw 3 dotplots for "a","b" and "c" factors, and then add an
> horizontal line at y=10 for panel "a", y=8 for panel "b" and y=6 for panel "4"

It's quite easy to do this with ggplot2 (http://had.co.nz/ggplot2) -
see http://had.co.nz/ggplot2/geom_vline.html for examples of both
common and specific reference lines.

Hadley

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.