您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“R語言的orrplot包實(shí)例分析”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“R語言的orrplot包實(shí)例分析”吧!
一 數(shù)據(jù)準(zhǔn)備
載入所需的R包,利用公共數(shù)據(jù)集mtcars進(jìn)行展示。
library(corrplot)head(mtcars) mpg cyl disp hp drat wt qsec vs am gear carbMazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1#計(jì)算變量之間的相關(guān)系數(shù)corr <- cor(mtcars)
二 相關(guān)系數(shù)展示
2.1 默認(rèn)參數(shù)展示
corrplot(corr)
2.2 更該形狀和顯示范圍
method,:指定形狀,可以是circle圓形(默認(rèn)),square方形, ellipse, 橢圓形,number數(shù)值,shade陰影,color顏色,pie餅圖。
type:指定顯示范圍,full完全(默認(rèn)),lower下三角,upper上三角。
corrplot(mat_cor, method = "number", type = "upper", title = "")corrplot(mat_cor, method = "pie", type = "lower", title = "下三角",mar = c(1,1,1,1))
2.3 更改顏色
可以使用自定義顏色或者brewer.pal函數(shù)的畫板。
corrplot(corr, method = "ellipse", col = colorRampPalette(c("red", "blue"))(10), title = "更改顏色")corrplot(corr, method = "number", col = RColorBrewer::brewer.pal(n=11, name = "RdYlGn"),title = "")
2.4 排序和聚類
order,:指定相關(guān)系數(shù)排序的方法, original原始順序,AOE特征向量角序,F(xiàn)PC第一主成分順序,hclust層次聚類順序,alphabet字母順序。
hclust.method:order參數(shù)為hclust時(shí)可指定hclust中方法,7種可選:complete, ward, single, average, mcquitty, median和centroid。
addrect:指定order參數(shù)為hclust時(shí)有效, 是否添加矩形框, 默認(rèn)不添加, 用整數(shù)指定即可添加。
corrplot(corr,method="color",order="hclust",title = "hclust聚類", diag = TRUE,hclust.method="average",addCoef.col = "blue")
2.5 組合展示
corrplot(corr, method = "circle", type = "upper", tl.pos = "d")corrplot(corr, add = TRUE, type = "lower", method = "number", diag = FALSE, tl.pos = "n", cl.pos = "n")
NOW,corrplot進(jìn)行相關(guān)性的可視化就簡(jiǎn)單介紹到這,可以根據(jù)自己的審美組合圖形,顏色等。
到此,相信大家對(duì)“R語言的orrplot包實(shí)例分析”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。