Some time ago I asked a question on how to remove unused factors in a bar chart, and I got a useful solution for that problem, thanks to @Aaron. Now, I am facing a very simi
To do this, you'll need to supply both a modified prepanel
function (which sets up the limits of each panel's plotting area) and a modified panel
function (which is responsible for plotting the data). In both cases, the key modification is to use x[, drop=TRUE]
to drop the unused levels:
library(lattice)
barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG, df, groups = METRIC,
scales = list(x = list(rot = 45, relation = 'free')),
prepanel = function(x,y,...) {
xx <- x[, drop = TRUE]
list(xlim = levels(xx),
xat=sort(unique(as.numeric(xx))))
},
panel = function(x,y,...) {
xx <- x[, drop = TRUE]
panel.barchart(xx, y, ...)
},
auto.key = list(columns = 2))