R語言可視化——畫臉譜圖

0引言

對高維數據的可視化是一個難點問題,臉譜圖是根據人的臉、嘴、面部表情、眼睛、頭髮、鼻子和耳朵的長短寬等特徵來刻畫不同維度之間的關係。將各個維度的數據轉化爲人們熟知的面部表情來展示,這樣的可視化圖能夠使人快速去獲取各個維度的信息,使得數據更加形象化。R語言畫臉譜圖的包不只一個,本節主要介紹aplpack包裏的faces函數的使用方法。所用的代碼來自faces函數的例子。完整代碼可以運行?faces查看。

1、臉譜圖的各個指標

臉譜圖的指標如下表所示:

臉譜圖的15個指標
1 臉的高度 2臉的寬度3 臉型4嘴巴厚度 5, 嘴巴寬度6 微笑7 眼睛的高度8 眼睛寬度 9 頭髮長度 10 頭髮寬度11頭髮風格12 鼻子高度13 鼻子寬度14 耳朵寬度15耳朵高度

2、參數介紹

下面是函數的主要參數:

> faces
function (xy, which.row, fill = FALSE, face.type = 1, nrow.plot, 
    ncol.plot, scale = TRUE, byrow = FALSE, main, labels, print.info = TRUE, 
    na.rm = FALSE, ncolors = 20, col.nose = rainbow(ncolors), 
    col.eyes = rainbow(ncolors, start = 0.6, end = 0.85), col.hair = terrain.colors(ncolors), 
    col.face = heat.colors(ncolors), col.lips = rainbow(ncolors, 
        start = 0, end = 0.2), col.ears = rainbow(ncolors, start = 0, 
        end = 0.2), plot.faces = TRUE, cex = 2) 

2.1 xy

這個參數輸入的是數據,類型可以是矩陣可以是數據框。一行觀測值一個臉譜圖。

2.2 face.type

這個參數是可以設置爲0、1、2、其他

參數設置 含義
0 白色
1 彩色
2 聖誕老人+彩色
其他 同1的效果:彩色

3、數據介紹

下面是數據,也是採用的R語言中內置的例子使用的數據。維度是七16組觀測。

> data(longley)
> longley
     GNP.deflator     GNP Unemployed Armed.Forces Population Year Employed
1947         83.0 234.289      235.6        159.0    107.608 1947   60.323
1948         88.5 259.426      232.5        145.6    108.632 1948   61.122
1949         88.2 258.054      368.2        161.6    109.773 1949   60.171
1950         89.5 284.599      335.1        165.0    110.929 1950   61.187
1951         96.2 328.975      209.9        309.9    112.075 1951   63.221
1952         98.1 346.999      193.2        359.4    113.270 1952   63.639
1953         99.0 365.385      187.0        354.7    115.094 1953   64.989
1954        100.0 363.112      357.8        335.0    116.219 1954   63.761
1955        101.2 397.469      290.4        304.8    117.388 1955   66.019
1956        104.6 419.180      282.2        285.7    118.734 1956   67.857
1957        108.4 442.769      293.6        279.8    120.445 1957   68.169
1958        110.8 444.546      468.1        263.7    121.950 1958   66.513
1959        112.6 482.704      381.3        255.2    123.366 1959   68.655
1960        114.2 502.601      393.1        251.4    125.368 1960   69.564
1961        115.7 518.173      480.6        257.2    127.852 1961   69.331
1962        116.9 554.894      400.7        282.7    130.081 1962   70.551

4、案例展示

> faces(longley[1:9,],face.type=0)
effect of variables:
 modified item       Var           
 "height of face   " "GNP.deflator"
 "width of face    " "GNP"         
 "structure of face" "Unemployed"  
 "height of mouth  " "Armed.Forces"
 "width of mouth   " "Population"  
 "smiling          " "Year"        
 "height of eyes   " "Employed"    
 "width of eyes    " "GNP.deflator"
 "height of hair   " "GNP"         
 "width of hair   "  "Unemployed"  
 "style of hair   "  "Armed.Forces"
 "height of nose  "  "Population"  
 "width of nose   "  "Year"        
 "width of ear    "  "Employed"    
 "height of ear   "  "GNP.deflator"

在這裏插入圖片描述

> faces(longley[1:9,],face.type=1)
effect of variables:
 modified item       Var           
 "height of face   " "GNP.deflator"
 "width of face    " "GNP"         
 "structure of face" "Unemployed"  
 "height of mouth  " "Armed.Forces"
 "width of mouth   " "Population"  
 "smiling          " "Year"        
 "height of eyes   " "Employed"    
 "width of eyes    " "GNP.deflator"
 "height of hair   " "GNP"         
 "width of hair   "  "Unemployed"  
 "style of hair   "  "Armed.Forces"
 "height of nose  "  "Population"  
 "width of nose   "  "Year"        
 "width of ear    "  "Employed"    
 "height of ear   "  "GNP.deflator"

在這裏插入圖片描述
注:代碼裏輸出的是十五個特徵對應的數據維度。

5、總結

最終希望大家能夠把自己的數據完美的可視化出來。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章