I have a box plot with multiple levels d$a + d$b
d = data.frame(value = c(1,2,3,100), a = c("A","A","B","A"), b = c("C","D","C","C") )
boxplot(d$value ~ d$a + d$b, horizontal = TRUE)
when you run that code you will see that the B.D combination still shows up but it is empty. How do I remove it?
This is just a toy example. In reality I have 40+ combinations and do not want to remove the blank one by hand.
You can first use interaction (together with its drop argument) to create a new column of your data.frame, then plot it:
d <- data.frame(value = c(1,2,3,100), a = c("A","A","B","A"), b = c("C","D","C","C"))
d <- within(d, interaction <- interaction(a, b, drop = TRUE))
boxplot(value ~ interaction, data = d, horizontal = TRUE)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With