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)
当您运行该代码时,您会看到B.D组合仍然显示但它是空的。如何删除它?
这只是一个玩具的例子。实际上我有40多种组合,并且不想手动删除空白组合。
1 个答案:
答案 0 :(得分:2)
您可以先使用interaction(及其drop参数)创建data.frame的新列,然后绘制它:
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)