2014-11-20 137 views
0

我是R和统计数据的新手。 我想要绘制两个分类变量,长度都是147 的向量每个表都关系:分类变量图与R

AgeGroup 
26-49 50-64 65 and over Under 26 
101  16  5   25 

Role 
A/C  C/H      Dietician 
6  8      2 
Doctor Healthcare Assistant Lab 
56  7      2 
Nurse Pharmacist    Phlebotomist 
54  5      1 
Radiographer     Therapist 
1        5 

这里读书的问题的答案后,从2012年我希望使用此命令来获取spineplot:

plot(mydata$Role,mydata$AgeGroup,xlab="Role",ylab="Age Group") 

但它返回:

Error in plot.window(...) : need finite 'xlim' values 
In addition: Warning messages: 
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 
2: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 
3: In min(x) : no non-missing arguments to min; returning Inf 
4: In max(x) : no non-missing arguments to max; returning -Inf 
5: In min(x) : no non-missing arguments to min; returning Inf 
6: In max(x) : no non-missing arguments to max; returning -Inf 

我猜警告消息1是告诉我,xycoords()试图 要挟范畴元素为数字数据,当它没有这样做 正在恢复来港,这给图()什么跟...共事。
总之,我没有理解什么,我该如何解决?

+0

有一个plot.table方法,为什么不试试:'with(mydata,plot(table(Role,AgeGroup),xlab =“Role”,ylab =“Age Group “)' – 2014-11-20 22:13:01

+0

谢谢,这看起来不错!现在我可以花一些时间弄清楚它是如何工作的:-) – Gerard 2014-11-20 22:54:29

+2

'with'创建一个本地环境,其中列名被解释为对象,在该env中,一个表对象被传递给'plot'。 'plot'函数是通用的(尝试输入'methods(plot)'),以便查找'table'-classs对象的正确方法并执行其工作。要查看未导出的'plot.table'的代码,您需要使用'getAnywhere(plot.table)' – 2014-11-20 23:27:09

回答

0

我想我还不如把我的意见在回答中:

有一个plot.table方法,为什么不尝试:用(MYDATA,图(表(角色,AgeGroup),xlab =“角色”,ylab =‘年龄组’) - BondedDust 2小时以前

with创建其中的列名被解释为对象的局部环境,和在该环境中,一个“table'-对象被传递给plotplot。函数是通用的(尝试输入methods(plot)),因此它查找'table'-classs对象的正确方法并完成其工作。要查看plot.table whi的代码ch不会导出,您需要使用getAnywhere(plot.table)

+0

理解文档和错误消息将花费我很长时间,您提供的帮助是非常宝贵,非常感谢。 – Gerard 2014-11-22 00:08:00