Dear R-help list,
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)
But I am doing something wrong, because it plots the histogram for
factor level EC_max =9 first and than straight over it the histogram
for factor level 36, so only 6 panels on the graph rather than 12.
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)
On 2/11/08, willem vervoort <willemvervoort at gmail.com> wrote:> Dear R-help list, > > 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) > > But I am doing something wrong, because it plots the histogram for > factor level EC_max =9 first and than straight over it the histogram > for factor level 36, so only 6 panels on the graph rather than 12. > > I searched the archives, but no luck so far.Look up the 'layout' argument in ?xyplot. By default, for 2 or more conditioning variables, the levels of the first two define columns and rows, and the rest are spread out over multiple pages. In your example, you could try layout = c(6, 2) for starters. -Deepayan
Possibly Parallel Threads
- lack of memory for logistic regression in R?
- Condition to factor (easy to remember)
- using "by" and indicies
- lattice: add a marginal histogram on top of the colorkey of a levelplot?
- unable to find inherited method for function "edges", for signature "ugsh", "missing"