繁体   English   中英

带R的分类变量的图

[英]plot of categorical variables with R

我是R和统计领域的新手。 我正在尝试绘制两个类别变量的关系,它们是长度为147的向量。每个类别的表是:

    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()试图将类别元素强制转换为数字数据,而如果这样做失败,则会返回NA,这将使plot()无法使用。
简而言之,我无法理解什么以及如何解决?

我想我也可以将我的评论放在答案中:

有一个plot.table方法,所以为什么不尝试:with(mydata,plot(table(Role,AgeGroup),xlab =“ Role”,ylab =“ Age Group”)– BondedDust 3小时前

with创建一个将列名解释为对象的本地环境,并在该环境内将“表”对象传递给plot plot函数是通用的(尝试键入methods(plot) ),因此它为“ table”类对象查找适当的方法并执行其工作。 要查看未导出的plot.table的代码,您需要使用getAnywhere(plot.table)

暂无
暂无

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

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