[R] how to plot numeric variable against several categories with lattice bwplot?

Luigi Marongiu
Thu, 13 Jan 2022 19:38:04 -0000

Hello,
I have a numerical variable (x) and a series of categories. I would
like to make a box plot of x against each of the categories. How can I
arrange the data so that I can accomplish it with lattice?
At the moment I got this:
```
df = data.frame(x = c(rep(1,5), rep(2,5), rep(3,5)),
y = rnorm(15),
f1 = rep(letters[1:5],3),
f2 = rep(letters[7:9],5),
f3 = c(rep(LETTERS[10:12],4), LETTERS[10:12]))
df$x = factor(df$x)
df$f1 = factor(df$f1)
df$f2 = factor(df$f2)
df$f3 = factor(df$f3)
library(lattice)
bwplot(y ~ x, data = df, auto.key = TRUE )
```
Also, is it possible to have the wishers in solid line?
Thank you