Some time ago I asked a question about how to remove unused factors in a histogram , and I got a useful solution for this problem, thanks to @Aaron. Now I have a very similar problem, but the solution that I used in the past does not work for this case.
This is the code to reproduce the data frame that I am using:
set.seed(17) df <- data.frame(BENCH = sprintf('bench-%s', sort(rep(letters[1:8], 4))), CLASS.CFG = sprintf('class-%s', c(rep('C', 4), rep('A', 4), rep('B', 8), rep('C', 8), rep('A', 4), rep('D', 4))), EXEC.CFG = rep(c('st', 'st', 'dyn', 'dyn'), 8), METRIC = rep(c('ipc', 'pwr'), 16), VALUE = runif(32))
Direct command to build this data frame:
library(lattice) barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG, df, groups = METRIC, scales = list(x = list(rot = 45, relation = 'free')), auto.key = list(columns = 2))
As you can see, I draw VALUE for each BENCH, limited by any possible combination of EXEC.CFG and CLASS.CFG (this is what I mean with nested factors), and using METRIC to create groups.
As a result, I get:

Even if I use βfreeβ scales for the X axis, there are some (unnecessary) gaps between some bands on the graph (for example, between bench-b and bench-g ).
I tried to apply the solution I got for my previous question as follows:
pl1 <- barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG, subset(df, CLASS.CFG == 'class-A'), groups = METRIC, auto.key = list(columns = 2)) pl2 <- barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG, subset(df, CLASS.CFG == 'class-B'), groups = METRIC) pl3 <- barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG, subset(df, CLASS.CFG == 'class-C'), groups = METRIC) pl4 <- barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG, subset(df, CLASS.CFG == 'class-D'), groups = METRIC) pls <- c(pl1, pl2, pl3, pl4) pls <- update(pls, scales = list(y = 'same')) pls
And this is the result that I get:

As you noticed, this graph is incorrect. It does not take into account nested factors, mixing the values ββfrom CLASS.CFG and EXEC.CFG in the panel names.
I struggled with this for a while, but to no avail. Does anyone know how this can be achieved? (Basically, what I'm trying to get is a plot similar to the first, but without spaces between bars).