我是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()试图 要挟范畴元素为数字数据,当它没有这样做 正在恢复来港,这给图()什么跟...共事。
总之,我没有理解什么,我该如何解决?
有一个plot.table方法,为什么不试试:'with(mydata,plot(table(Role,AgeGroup),xlab =“Role”,ylab =“Age Group “)' – 2014-11-20 22:13:01
谢谢,这看起来不错!现在我可以花一些时间弄清楚它是如何工作的:-) – Gerard 2014-11-20 22:54:29
'with'创建一个本地环境,其中列名被解释为对象,在该env中,一个表对象被传递给'plot'。 'plot'函数是通用的(尝试输入'methods(plot)'),以便查找'table'-classs对象的正确方法并执行其工作。要查看未导出的'plot.table'的代码,您需要使用'getAnywhere(plot.table)' – 2014-11-20 23:27:09