Bernardo
Bernardo

Reputation: 426

Boxplot including an "All" box

Consider the dataframe

df = data.frame(x = rnorm(33),cat = gl(3,11))

When I plot a boxplot of x separated by each level of cat this is what I get

boxplot(df$x ~ df$cat)

enter image description here

Is it possible to include another box in the same plot showing all the values of x?

boxplot(df$x,xlab = "x")

enter image description here

Upvotes: 0

Views: 59

Answers (1)

Jake Burkhead
Jake Burkhead

Reputation: 6535

boxplot(x ~ cat, data = rbind(df, data.frame(x = df$x, cat = "all")))

enter image description here

Upvotes: 2

Related Questions