bar = function() { barchart(yield ~ variety | site, data = barley, #barchart(yield ~ variety , data = barley, groups = year, layout = c(1,6), stack = TRUE, auto.key = list(space = "right"), ylab = "Barley Yield (bushels/acre)", scales = list(x = list(rot = 45))) } # How to allow for either the first barchart or the second one? # Use a conditional bar1 = function(which=1, factor=barley$site) { if (which == 1) { barchart(yield ~ variety | factor, data = barley, groups = year, layout = c(1,6), stack = TRUE, auto.key = list(space = "right"), ylab = "Barley Yield (bushels/acre)", scales = list(x = list(rot = 45))) } else { barchart(yield ~ variety , data = barley, groups = year, layout = c(1,6), stack = TRUE, auto.key = list(space = "right"), ylab = "Barley Yield (bushels/acre)", scales = list(x = list(rot = 45))) } } # NOTE USE OF # groups (factor within a bar) # | factor : number of individual plots