Plot empty groups in boxplot

混江龙づ霸主 提交于 2019-12-10 22:41:31

问题


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)

than I get the plot without group 3 (wich I cant show because I did not have "10 reputation")

I found some solutions for removing empty groups via google but my problem is the other way around.

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


回答1:


You can get the group on the x-axis by

boxplot(b ~ a , df, na.action=na.pass)

Or

boxplot(b~factor(a), df)


来源:https://stackoverflow.com/questions/29185996/plot-empty-groups-in-boxplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!