2014-11-20 139 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