File: clusplot-out.R

package info (click to toggle)
cluster 1.9.8-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 944 kB
  • ctags: 182
  • sloc: ansic: 1,388; fortran: 1,038; sh: 28; makefile: 22
file content (30 lines) | stat: -rw-r--r-- 860 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
### SETUP
library(cluster)

### clusplot() & pam() RESULT checking ...

## plotting votes.diss(dissimilarity) in a bivariate plot and
## partitioning into 2 clusters
data(votes.repub)
votes.diss <- daisy(votes.repub)
for(k in 2:4) {
    votes.clus <- pam(votes.diss, k, diss = TRUE)$clustering
    print(clusplot(votes.diss, votes.clus, diss = TRUE, shade = TRUE))
}

## plotting iris (dataframe) in a 2-dimensional plot and partitioning
## into 3 clusters.
data(iris)
iris.x <- iris[, 1:4]

for(k in 2:5)
    print(clusplot(iris.x, pam(iris.x, k)$clustering, diss = FALSE))


.Random.seed <- c(0,rep(7654,3))
## generate 25 objects, divided into 2 clusters.
x <- rbind(cbind(rnorm(10,0,0.5), rnorm(10,0,0.5)),
           cbind(rnorm(15,5,0.5), rnorm(15,5,0.5)))
print.default(clusplot(px2 <- pam(x, 2)))

clusplot(px2, labels = 2, col.p = 1 + px2$clustering)