clusplot.default
位於 cluster
包(package)。 說明
創建可視化數據分區(聚類)的二變量圖。所有觀察結果均使用主成分或多維標度由圖中的點表示。在每個簇周圍繪製一個橢圓。
用法
## Default S3 method:
clusplot(x, clus, diss = FALSE,
s.x.2d = mkCheckX(x, diss), stand = FALSE,
lines = 2, shade = FALSE, color = FALSE,
labels= 0, plotchar = TRUE,
col.p = "dark green", col.txt = col.p,
col.clus = if(color) c(2, 4, 6, 3) else 5, cex = 1, cex.txt = cex,
span = TRUE,
add = FALSE,
xlim = NULL, ylim = NULL,
main = paste("CLUSPLOT(", deparse1(substitute(x)),")"),
sub = paste("These two components explain",
round(100 * var.dec, digits = 2), "% of the point variability."),
xlab = "Component 1", ylab = "Component 2",
verbose = getOption("verbose"),
...)
參數
x |
矩陣或 DataFrame ,或相異矩陣,具體取決於 對於矩陣(類似),每行對應一個觀察值,每列對應一個變量。所有變量都必須是數字。允許缺失值 ( 如果是相異矩陣, |
clus |
長度為 n 的向量,表示 |
diss |
邏輯指示 |
s.x.2d |
|
stand |
邏輯標誌:如果為 true,則二維圖中 n 個觀測值的表示是標準化的。 |
lines |
如果 E1 和 E2 在通過
|
shade |
邏輯標誌:如果為 TRUE,則橢圓的陰影與其密度有關。密度是簇中的點數除以橢圓麵積。 |
color |
邏輯標誌:如果為 TRUE,則橢圓根據其密度著色。隨著密度的增加,顏色有淺藍色、淺綠色、紅色和紫色。要在圖形設備上看到這些顏色,應選擇適當的配色方案(我們建議使用白色背景)。 |
labels |
整數代碼,當前為 0,1,2,3,4 和 5 之一。如果
向量 將不考慮 |
plotchar |
邏輯標誌:如果為 TRUE,則屬於不同簇的點的繪圖符號不同。 |
span |
邏輯標誌:如果為 TRUE,則每個簇由包含其所有點的最小麵積的橢圓表示。 (這是最小體積橢球體的特例。) 還有一些特殊情況:當一個簇僅由一個點組成時,會在它周圍畫一個小圓圈。當簇中的點落在一條直線上時, |
add |
邏輯指示是否應將省略號(如果 |
col.p |
用於觀察點的顏色代碼。 |
col.txt |
用於標簽的顏色代碼(如果 |
col.clus |
橢圓的顏色代碼(及其標簽);如果顏色為 false(默認情況下),則隻有一個。 |
cex , cex.txt |
字符擴展(大小),分別用於點符號和點標簽。 |
xlim , ylim |
長度為 2 的數值向量,給出 x 和 y 範圍,如 |
main |
情節的主標題;默認情況下,會構建一個。 |
sub |
情節的副標題;默認情況下,會構建一個。 |
xlab , ylab |
繪圖的 x 軸和 y 軸標簽,帶默認值。 |
verbose |
邏輯指示是否應該有額外的診斷輸出;主要用於‘debugging’。 |
... |
還可以提供更多圖形參數,請參閱 |
細節
clusplot
分別使用函數調用 princomp(*, cor = (ncol(x) > 2))
或 cmdscale(*, add=TRUE)
,具體取決於 diss
為 false 或 true。這些函數是數據縮減技術,用於表示雙變量圖中的數據。
然後繪製橢圓來指示簇。繪圖的進一步布局由可選參數確定。
值
包含組件的不可見列表:
Distances |
什麽時候 |
Shading |
長度為 k 的向量(其中 k 是簇的數量),包含每個簇的陰影量。設 y 為向量,其中元素 i 是簇 i 中的點數與橢圓 i 的麵積之間的比率。當簇i是線段時,y[i]和簇的密度被設置為 |
副作用
在當前圖形設備上繪製聚類的可視化顯示。
注意
當我們有 4 個或更少的簇時,color=TRUE
會為每個簇賦予不同的顏色。當簇數超過 4 個時,clusplot 使用函數 pam
將密度聚類為 4 組,使得密度幾乎相同的橢圓具有相同的顏色。 col.clus
指定使用的顏色。
col.p
和col.txt
參數,添加為R,被回收以具有觀察數量的長度。如果col.p
有多個值,使用color = TRUE
由於點顏色和橢圓顏色的混合,可能會造成混淆。
例子
## plotting votes.diss(dissimilarity) in a bivariate plot and
## partitioning into 2 clusters
data(votes.repub)
votes.diss <- daisy(votes.repub)
pamv <- pam(votes.diss, 2, diss = TRUE)
clusplot(pamv, shade = TRUE)
## is the same as
votes.clus <- pamv$clustering
clusplot(votes.diss, votes.clus, diss = TRUE, shade = TRUE)
## Now look at components 3 and 2 instead of 1 and 2:
str(cMDS <- cmdscale(votes.diss, k=3, add=TRUE))
clusplot(pamv, s.x.2d = list(x=cMDS$points[, c(3,2)],
labs=rownames(votes.repub), var.dec=NA),
shade = TRUE, col.p = votes.clus,
sub="", xlab = "Component 3", ylab = "Component 2")
clusplot(pamv, col.p = votes.clus, labels = 4)# color points and label ellipses
# "simple" cheap ellipses: larger than minimum volume:
# here they are *added* to the previous plot:
clusplot(pamv, span = FALSE, add = TRUE, col.clus = "midnightblue")
## Setting a small *label* size:
clusplot(votes.diss, votes.clus, diss = TRUE, labels = 3, cex.txt = 0.6)
if(dev.interactive()) { # uses identify() *interactively* :
clusplot(votes.diss, votes.clus, diss = TRUE, shade = TRUE, labels = 1)
clusplot(votes.diss, votes.clus, diss = TRUE, labels = 5)# ident. only points
}
## plotting iris (data frame) in a 2-dimensional plot and partitioning
## into 3 clusters.
data(iris)
iris.x <- iris[, 1:4]
cl3 <- pam(iris.x, 3)$clustering
op <- par(mfrow= c(2,2))
clusplot(iris.x, cl3, color = TRUE)
U <- par("usr")
## zoom in :
rect(0,-1, 2,1, border = "orange", lwd=2)
clusplot(iris.x, cl3, color = TRUE, xlim = c(0,2), ylim = c(-1,1))
box(col="orange",lwd=2); mtext("sub region", font = 4, cex = 2)
## or zoom out :
clusplot(iris.x, cl3, color = TRUE, xlim = c(-4,4), ylim = c(-4,4))
mtext("'super' region", font = 4, cex = 2)
rect(U[1],U[3], U[2],U[4], lwd=2, lty = 3)
# reset graphics
par(op)
參考
Pison, G., Struyf, A. and Rousseeuw, P.J. (1999)
Displaying a Clustering with CLUSPLOT,
Computational Statistics and Data Analysis, 30, 381-392.
Kaufman, L. and Rousseeuw, P.J. (1990). Finding Groups in Data: An Introduction to Cluster Analysis. Wiley, New York.
Struyf, A., Hubert, M. and Rousseeuw, P.J. (1997). Integrating Robust Clustering Techniques in S-PLUS, Computational Statistics and Data Analysis, 26, 17-37.
也可以看看
princomp
, cmdscale
, pam
, clara
, daisy
, par
, identify
, cov.mve
, clusplot.partition
。
相關用法
- R clusplot (分區對象的)雙變量聚類圖
- R clusGap 用於估計聚類數量的間隙統計
- R clara 集群大型應用程序
- R chorSub Kola 數據 C 範圍的子集
- R coef.hclust “hclust”對象的凝聚/分裂係數
- R summary.clara “clara”對象的摘要方法
- R diana 分裂分析聚類
- R pluton 鈈同位素成分批次
- R votes.repub 總統選舉中共和黨候選人的投票
- R agnes 凝聚嵌套(層次聚類)
- R print.mona MONA 對象的打印方法
- R print.clara CLARA 對象的打印方法
- R mona 二元變量的單論分析聚類
- R plot.diana 分裂層次聚類圖
- R plot.mona 一元分裂層次聚類的旗幟
- R bannerplot 繪圖橫幅(層次聚類)
- R plot.partition 數據集分區圖
- R summary.agnes “agnes”對象的摘要方法
- R pltree 繪製層次聚類的聚類樹
- R summary.mona “mona”對象的摘要方法
- R plantTraits 植物物種性狀數據
- R plot.agnes 凝聚層次聚類圖
- R print.agnes AGNES 對象的打印方法
- R pam 圍繞 Medoid 進行分區
- R volume.ellipsoid 計算(橢球體的)體積
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Bivariate Cluster Plot (clusplot) Default Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。