Re: [R] lattice histogram

2007-03-05 Thread Renaud Lancelot
See argument drop.unused.levels in xyplot. You will also need to
manage the case n = 0 for dispalying the mean and stdv.

Best,

Renaud

histogram(~ resp | group, drop.unused.levels = FALSE,
  panel = function(x, ...){
std - if(length(x)  0) format(round(sd(x), 2), nsmall = 2) else NA
n - length(x)
m - if(length(x)  0) format(round(mean(x), 2), nsmall = 2) else NA
panel.histogram(x, ...)
x1 - unit(1, npc) - unit(2, mm)
y1 - unit(1, npc) - unit(2, mm)
grid.text(label = bquote(n == .(n)), x = x1, y = y1, just = right)
grid.text(label = bquote(hat(m) == .(m)), x = x1, y = y1 - unit(1,
lines), just = right)
grid.text(label = bquote(hat(s) == .(std)), x = x1, y = y1 -
unit(2, lines), just = right)
})


2007/3/5, Aimin Yan [EMAIL PROTECTED]:
 thank you very much.  Your code almost solve my problem, but I have a
 further question.
 In my data, there is no observation in some group, I want to label that
 panel by
 n=0
 hat(m)=NA
 hat(s)=NA.

 I try to modify your panel function, but it doesn't work out. Do you know
 how to add something to your panel
   function so that it can deal with some group that has 0 observation.

 Aimin

 At 02:54 AM 3/4/2007, Renaud Lancelot wrote:
 Here is an example using the grid package to annotate the graphs:
 
 library(lattice)
 library(grid)
 resp  - rnorm(200)
 group - sample(c(G1, G2, G3), replace = TRUE, size = 100)
 histogram(~ resp | group,
   panel = function(x, ...){
 std - round(sd(x), 2)
 n - length(x)
 m - round(mean(x), 2)
 panel.histogram(x, ...)
 x1 - unit(1, npc) - unit(2, mm)
 y1 - unit(1, npc) - unit(2, mm)
 grid.text(label = bquote(n == .(n)), x = x1, y = y1, just = right)
 grid.text(label = bquote(hat(m) == .(m)), x = x1, y = y1 - unit(1,
 lines), just = right)
 grid.text(label = bquote(hat(s) == .(std)), x = x1, y = y1 -
 unit(2, lines), just = right)
 })
 Best,
 
 Renaud
 
 2007/3/4, Aimin Yan [EMAIL PROTECTED]:
 How to add mean,sd, number of observation in each panel for lattice
 histogram?
 
 Aimin
 
 __
 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.
 
 
 --
 Renaud LANCELOT
 Département Systèmes Biologiques du CIRAD
 CIRAD, Biological Systems Department
 
 Campus International de Baillarguet
 TA 30 / B
 F34398 Montpellier
 Tel   +33 (0)4 67 59 37 17
 Secr. +33 (0)4 67 59 37 37
 Fax   +33 (0)4 67 59 37 95





-- 
Renaud LANCELOT
Département Systèmes Biologiques du CIRAD
CIRAD, Biological Systems Department

Campus International de Baillarguet
TA 30 / B
F34398 Montpellier
Tel   +33 (0)4 67 59 37 17
Secr. +33 (0)4 67 59 37 37
Fax   +33 (0)4 67 59 37 95

__
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] lattice histogram

2007-03-04 Thread Renaud Lancelot
Here is an example using the grid package to annotate the graphs:

library(lattice)
library(grid)
resp  - rnorm(200)
group - sample(c(G1, G2, G3), replace = TRUE, size = 100)
histogram(~ resp | group,
  panel = function(x, ...){
std - round(sd(x), 2)
n - length(x)
m - round(mean(x), 2)
panel.histogram(x, ...)
x1 - unit(1, npc) - unit(2, mm)
y1 - unit(1, npc) - unit(2, mm)
grid.text(label = bquote(n == .(n)), x = x1, y = y1, just = right)
grid.text(label = bquote(hat(m) == .(m)), x = x1, y = y1 - unit(1,
lines), just = right)
grid.text(label = bquote(hat(s) == .(std)), x = x1, y = y1 -
unit(2, lines), just = right)
})
Best,

Renaud

2007/3/4, Aimin Yan [EMAIL PROTECTED]:
 How to add mean,sd, number of observation in each panel for lattice histogram?

 Aimin

 __
 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.



-- 
Renaud LANCELOT
Département Systèmes Biologiques du CIRAD
CIRAD, Biological Systems Department

Campus International de Baillarguet
TA 30 / B
F34398 Montpellier
Tel   +33 (0)4 67 59 37 17
Secr. +33 (0)4 67 59 37 37
Fax   +33 (0)4 67 59 37 95

__
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] lattice histogram

2007-03-04 Thread steve
Hi,

When I tried this the groups had sizes 36 30 34 as expected, but
the annotations n =  were 68 72 60 - twice as large. I don't 
understand why.

Steve

Renaud Lancelot wrote:
 Here is an example using the grid package to annotate the graphs:
 
 library(lattice)
 library(grid)
 resp  - rnorm(200)
 group - sample(c(G1, G2, G3), replace = TRUE, size = 100)
 histogram(~ resp | group,
   panel = function(x, ...){
 std - round(sd(x), 2)
 n - length(x)
 m - round(mean(x), 2)
 panel.histogram(x, ...)
 x1 - unit(1, npc) - unit(2, mm)
 y1 - unit(1, npc) - unit(2, mm)
 grid.text(label = bquote(n == .(n)), x = x1, y = y1, just = right)
 grid.text(label = bquote(hat(m) == .(m)), x = x1, y = y1 - unit(1,
 lines), just = right)
 grid.text(label = bquote(hat(s) == .(std)), x = x1, y = y1 -
 unit(2, lines), just = right)
 })

__
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] lattice histogram

2007-03-04 Thread Mendiburu, Felipe \(CIP\)
Steve,

it says resp  - rnorm(200) must be resp  - rnorm(100) 

regards

Felipe

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of steve
Sent: Sunday, March 04, 2007 8:58 AM
To: r-help@stat.math.ethz.ch
Subject: Re: [R] lattice histogram


Hi,

When I tried this the groups had sizes 36 30 34 as expected, but
the annotations n =  were 68 72 60 - twice as large. I don't 
understand why.

Steve

Renaud Lancelot wrote:
 Here is an example using the grid package to annotate the graphs:
 
 library(lattice)
 library(grid)
 resp  - rnorm(200)
 group - sample(c(G1, G2, G3), replace = TRUE, size = 100)
 histogram(~ resp | group,
   panel = function(x, ...){
 std - round(sd(x), 2)
 n - length(x)
 m - round(mean(x), 2)
 panel.histogram(x, ...)
 x1 - unit(1, npc) - unit(2, mm)
 y1 - unit(1, npc) - unit(2, mm)
 grid.text(label = bquote(n == .(n)), x = x1, y = y1, just = right)
 grid.text(label = bquote(hat(m) == .(m)), x = x1, y = y1 - unit(1,
 lines), just = right)
 grid.text(label = bquote(hat(s) == .(std)), x = x1, y = y1 -
 unit(2, lines), just = right)
 })

__
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.

__
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] lattice histogram

2007-03-04 Thread Aimin Yan
thank you very much.  Your code almost solve my problem, but I have a 
further question.
In my data, there is no observation in some group, I want to label that 
panel by
n=0
hat(m)=NA
hat(s)=NA.

I try to modify your panel function, but it doesn't work out. Do you know 
how to add something to your panel
  function so that it can deal with some group that has 0 observation.

Aimin

At 02:54 AM 3/4/2007, Renaud Lancelot wrote:
Here is an example using the grid package to annotate the graphs:

library(lattice)
library(grid)
resp  - rnorm(200)
group - sample(c(G1, G2, G3), replace = TRUE, size = 100)
histogram(~ resp | group,
  panel = function(x, ...){
std - round(sd(x), 2)
n - length(x)
m - round(mean(x), 2)
panel.histogram(x, ...)
x1 - unit(1, npc) - unit(2, mm)
y1 - unit(1, npc) - unit(2, mm)
grid.text(label = bquote(n == .(n)), x = x1, y = y1, just = right)
grid.text(label = bquote(hat(m) == .(m)), x = x1, y = y1 - unit(1,
lines), just = right)
grid.text(label = bquote(hat(s) == .(std)), x = x1, y = y1 -
unit(2, lines), just = right)
})
Best,

Renaud

2007/3/4, Aimin Yan [EMAIL PROTECTED]:
How to add mean,sd, number of observation in each panel for lattice 
histogram?

Aimin

__
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.


--
Renaud LANCELOT
Département Systèmes Biologiques du CIRAD
CIRAD, Biological Systems Department

Campus International de Baillarguet
TA 30 / B
F34398 Montpellier
Tel   +33 (0)4 67 59 37 17
Secr. +33 (0)4 67 59 37 37
Fax   +33 (0)4 67 59 37 95

__
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.


[R] lattice histogram

2007-03-03 Thread Aimin Yan
How to add mean,sd, number of observation in each panel for lattice histogram?

Aimin

__
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] lattice: histogram of factor variable

2006-11-10 Thread Deepayan Sarkar
On 11/10/06, Albrecht, Dr. Stefan (AZ Private Equity Partner)
[EMAIL PROTECTED] wrote:
 Dear all,

 I am encountering a problem with lattice in the current version 0.14-13
 with R version 2.4.0 on a Windows XP system.
 For example,

 histogram(~voice.part, singer)

 is not labeling the x labels according to the factor levels of
 voice.part, which it should do (and has done in former versions of
 lattice, as far as I remember).

I will fix that, but you shouldn't really be using histograms for
factors. Use barchart instead, e.g.

barchart(table(voice.part) ~ levels(voice.part), singer, origin = 0)

-Deepayan

 In addition, I get the warnings
 Warning messages:
 1: arguments 'include.lowest', 'right' are not made use of in:
 hist.default(x, breaks = breaks, plot = FALSE, include.lowest =
 include.lowest,
 2: arguments 'include.lowest', 'right' are not made use of in:
 hist.default(x, breaks = breaks, plot = FALSE, include.lowest =
 include.lowest,
 

 which are a bit annoying, but (hopefully) not a real problem.

 Does anybody have a simple help (for the x labels)?

 Many thanks and best regards,

 Stefan

 
 Dr. Stefan Albrecht, CFA
 Allianz Private Equity Partners GmbH
 Giselastr. 4 | 80802 Munich | Germany

 Phone: +49.(0)89.3800.18317
 Fax: +49.(0)89.3800.818317
 EMail: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
 Web: www.apep.com http://www.apep.com/


 Please note my new email address:
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]



 [[alternative HTML version deleted]]

 __
 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.



-- 
http://www.stat.wisc.edu/~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.


[R] lattice histogram finetuning

2006-01-31 Thread Patrick Kuss
Dear list,

I have some difficulties fine-tuning a lattice conditional histogram plot and
found little help in the documentation.
My dataset consists of plant flowering ages from 3 different altitudes and 3
successional sites at each altitudinal level.

My questions are:

How do I avoid that lattice automatically sorts the different $condlevels
alphabetically? I need:
hist$condlevels$succession - list(early,mid,late)
 # not early,late,mid
hist$condlevels$site - list(FU,SP,JU)

Additionally, how do I add a vertical line indicating the mean flowering age at
each panel?

And how do I assure breaks to happen for each year?
hist$panel.args.common$breaks


Happy for any suggestions

Patrick


# Flowering age at different altitudes and successional site

FU.e - round(rnorm(20,mean=9,sd=1),dig=0)
FU.m - round(rnorm(20,mean=12,sd=1),dig=0)
FU.l - round(rnorm(20,mean=15,sd=1),dig=0)
SP.e - round(rnorm(20,mean=8,sd=1),dig=0)
SP.m - round(rnorm(20,mean=11,sd=1),dig=0)
SP.l - round(rnorm(20,mean=14,sd=1),dig=0)
JU.e - round(rnorm(20,mean=7,sd=1),dig=0)
JU.m - round(rnorm(20,mean=10,sd=1),dig=0)
JU.l - round(rnorm(20,mean=13,sd=1),dig=0)

age - c(FU.e,FU.m,FU.l,SP.e,SP.m,SP.l,JU.e,JU.m,JU.l)
site - rep(c(FU,SP,JU),each=60)
succession - rep(c(early,mid,late),each=20,times=3)

CT.flow - data.frame(site,succession,age)

library(lattice)
trellis.device(color=F)

hist - histogram(~age|succession*site,data=CT.flow)
hist



--
Patrick Kuss
PhD-student
Institute of Botany
University of Basel
Schönbeinstr. 6
CH-4056 Basel
+41 61 267 2976

__
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


Re: [R] lattice histogram finetuning

2006-01-31 Thread Jacques VESLOT
it looks like a barchart rather than an histogram (?).
if it is, you can do something like that:

CT.flow$age - factor(CT.flow$age)
CT.flow$succession - 
factor(CT.flow$succession,levels=c(early,mid,late))

ct - expand.grid(  succession=levels(CT.flow$succession),
site=levels(CT.flow$site),
age=levels(CT.flow$age)

ct$eff - as.vector(ftable(xtabs(~.,CT.flow)))

barchart(eff~age|site*succession,horiz=F,ct)



Patrick Kuss a écrit :

Dear list,

I have some difficulties fine-tuning a lattice conditional histogram plot and
found little help in the documentation.
My dataset consists of plant flowering ages from 3 different altitudes and 3
successional sites at each altitudinal level.

My questions are:

How do I avoid that lattice automatically sorts the different $condlevels
alphabetically? I need:
hist$condlevels$succession - list(early,mid,late)
 # not early,late,mid
hist$condlevels$site - list(FU,SP,JU)

Additionally, how do I add a vertical line indicating the mean flowering age at
each panel?

And how do I assure breaks to happen for each year?
hist$panel.args.common$breaks


Happy for any suggestions

Patrick


# Flowering age at different altitudes and successional site

FU.e - round(rnorm(20,mean=9,sd=1),dig=0)
FU.m - round(rnorm(20,mean=12,sd=1),dig=0)
FU.l - round(rnorm(20,mean=15,sd=1),dig=0)
SP.e - round(rnorm(20,mean=8,sd=1),dig=0)
SP.m - round(rnorm(20,mean=11,sd=1),dig=0)
SP.l - round(rnorm(20,mean=14,sd=1),dig=0)
JU.e - round(rnorm(20,mean=7,sd=1),dig=0)
JU.m - round(rnorm(20,mean=10,sd=1),dig=0)
JU.l - round(rnorm(20,mean=13,sd=1),dig=0)

age - c(FU.e,FU.m,FU.l,SP.e,SP.m,SP.l,JU.e,JU.m,JU.l)
site - rep(c(FU,SP,JU),each=60)
succession - rep(c(early,mid,late),each=20,times=3)

CT.flow - data.frame(site,succession,age)

library(lattice)
trellis.device(color=F)

hist - histogram(~age|succession*site,data=CT.flow)
hist



--
Patrick Kuss
PhD-student
Institute of Botany
University of Basel
Schönbeinstr. 6
CH-4056 Basel
+41 61 267 2976

__
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

  


__
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