简体   繁体   English

R合并箱线图

[英]R Merging Boxplots

I am trying to use R to show a merged boxplot, I am sure this is easy, I just am missing something: 我正在尝试使用R显示合并的箱线图,我敢肯定这很容易,只是缺少了一些东西:

boxplot(WHO$Male, WHO$Female, ylim=c(0,100))

boxplot(WHO$Female ~ WHO$Year, ylim=c(0,100))
boxplot(WHO$Male ~ WHO$Year, ylim=c(0,100))

All three work, but when I try: 这三个都可以,但是当我尝试时:

boxplot(WHO$Male ~ WHO$Year, WHO$Female ~ WHO$Year, ylim=c(0,100))

It returns: 它返回:

Error in as.data.frame.default(data) : 
   cannot coerce class ""formula"" to a data.frame

Note, Year, only contains three numbers, 1990, 2000, 2010 请注意,年份仅包含三个数字,1990、2000、2010

> head(WHO)
  Year WHO.region      Country Male Female
1 1990     Africa      Algeria   66     68
2 1990     Africa       Angola   39     43
3 1990     Africa        Benin   45     50
4 1990     Africa     Botswana   63     66
5 1990     Africa Burkina Faso   45     49
6 1990     Africa      Burundi   47     50

reshape2 package does something similar. reshape2包做类似的事情。 Actually there was quite similar question - Plot multiple boxplot in one graph , maybe it will be helpful. 实际上存在一个非常类似的问题- 在一张图中绘制多个箱线图 ,也许会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM