# [R] Histogram in Lattice with 3 factors

From: willem vervoort <willemvervoort_at_gmail.com>
Date: Tue, 12 Feb 2008 09:30:01 +1100

I am trying to construct a lattice histogram using 3 factors.

My dataframe looks like this: (simulating a waterbalance over groundwater with different salinities)

```s      days   model    EC    EC_max
0.4     1        "A"       10      9
0.42   2        "A"       10      9
0.44   3        "A"       10       9
:        :          :           :         :
0.4      1        "B"      10      9
:        :          :          :         :
0.4      1        "A"      30        9
:        :          :          :           :
0.4      1        "A"      30        36

```

Anyway you get the gist
EC_max has two levels 9 and 36, EC has 3 levels 10, 30 and 70, and model has two levels ("A" and "B"). There are say 365 days and s is the variable of interest (soil saturation)

Can maybe be reproduced with:
data <- data.frame(s = rnorm(2*3*365*2),rep(1:365,12), model = sort(rep(c("A","B"),6*365)),

EC = rep(sort(rep(c(10,30,70),365*2)),2), EC_max = rep(sort(rep(c(9,36),3*365)),2))

I would like to plot histograms with the three factors using Lattice so I had the following code:

my.strip <- function(which.given, ..., factor.levels) {

```            levs <- if (which.given == 1)  c("Model A","Model B")
else {if(which.given == 2) paste("EC =
",as.character(EC),"dS/m")
else paste("ECmax = ",as.character(EC_max),"dS/m")}
strip.default(which.given, ..., factor.levels = levs)
}

```

histogram(~s|model*as.factor(EC)*as.factor(EC_max),data=Store,xlab="soil saturation",type="density",strip=my.strip)

I searched the archives, but no luck so far.

Any help is appreciated

Willem

```platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status
major          2
minor          6.1
year           2007
month          11
day            26
svn rev        43537
language       R
```

version.string R version 2.6.1 (2007-11-26)

R-help_at_r-project.org 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. Received on Mon 11 Feb 2008 - 22:35:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 11 Feb 2008 - 23:30:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.