gpt4 book ai didi

从具有多个级别的箱形图中删除空级别

转载 作者:行者123 更新时间:2023-12-02 01:30:11 29 4
gpt4 key购买 nike

我有一个多层次的箱形图 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)

当您运行该代码时,您会看到 B.D 组合仍然显示,但它是空的。如何删除它?

这只是一个玩具示例。实际上,我有 40 多种组合,不想手动删除空白组合。

最佳答案

您可以先使用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)

enter image description here

关于从具有多个级别的箱形图中删除空级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34735044/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com