You may try this:
dotplot(car ~ mpg | as.factor(cyl), data=df, layout=c(3,1),
pch = 19, groups = carb < 2, col = c("blue", "red"))
The groups
argument carb < 2
results in a logical vector. Alphabetically FALSE
comes before TRUE
. Thus, cases where carb < 2
is FALSE get the first colour (blue), and cases where carb < 2 get the second colour, red.
From ?dotplot
about group
argument:
A variable or expression to be evaluated in data, expected to act as a grouping variable within each panel, typically used to distinguish different groups by varying graphical parameters like color and line type.