在boxplot中绘制空组 [英] Plot empty groups in boxplot
问题描述
我想绘制一些特定样式的箱形图以进行比较。
但是当一个组为空时,该组未绘制。
I want to plot a lot of boxplots in on particular style to compare them. But when a group is empty the group "isnt ploted".
让我说我有一个数据框:
lets say I have a dataframe:
a b
1 1 5
2 1 4
3 1 6
4 1 4
5 2 9
6 2 8
7 2 9
8 3 NaN
9 3 NaN
10 3 NaN
11 4 2
12 4 8
,然后使用箱线图进行绘制:
and I use boxplot to plot it:
boxplot(b ~ a , df)
没有组3的情节
(我无法显示,因为我没有 10个声望)
than I get the plot without group 3 (wich I cant show because I did not have "10 reputation")
我找到了一些通过Google删除空组的解决方案,但是我问题是相反的。
I found some solutions for removing empty groups via google but my problem is the other way around.
然后我通过at = c(1,2,4)找到了解决方案,但是当我用python生成Rscript且不同的组为空时,我希望
And I found the solution via at=c(1,2,4) but as I generate an Rscript with python and different groups are empty I would prefer, that the groups aren't dropped at all.
哦,我认为我没有时间去处理其他软件包。
因此,如果没有这些解决方案,我将不胜感激。
Oh I don't think I have the time to grapple with additional packages. Therefore I would be thankfull for solutions without them.
关于犬,
Regards, canis
推荐答案
您可以通过xp轴上的组
You can get the group on the x-axis by
boxplot(b ~ a , df, na.action=na.pass)
或
boxplot(b~factor(a), df)
这篇关于在boxplot中绘制空组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!