I have a data that looks like this:
cats = c("cat1", "cat2", "cat3", "cat4")
df = data.frame(a = rnorm(100), b = as.factor(rep(cats, 25)))
When I plot it I get something like this:
ggplot(data = df) + geom_boxplot(aes(x = b, y = a, fill = b))
But what can I do if I'd like them to be in the order cat4, cat3, cat2, cat1 on the x-axis. Or even in a completely different order?