data("iris")
d <- dist(iris[-5])
## plot original matrix
res <- dissplot(d, method = NA)
## plot reordered matrix using the nearest insertion algorithm (from tsp)
res <- dissplot(d, method = "tsp",
options = list(main = "Seriation (TSP)"))
## cluster with pam (we know iris has 3 clusters)
library("cluster")
l <- pam(d, 3, cluster.only = TRUE)
## we use a grid layout to place several plots on a page
grid.newpage()
pushViewport(viewport(layout=grid.layout(nrow = 2, ncol = 2),
gp = gpar(fontsize = 8)))
pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 1))
## visualize the clustering
res <- dissplot(d, l, method = "chen",
options = list(main = "PAM + Seriation (Chen) - standard",
newpage = FALSE))
popViewport()
pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 2))
## more visualization options
## threshold
plot(res, options = list(main = "PAM + Seriation (Chen) - threshold",
threshold = 1.5, newpage = FALSE))
popViewport()
pushViewport(viewport(layout.pos.row = 2, layout.pos.col = 1))
## color: use 10 shades of blue
plot(res, options = list(main = "PAM + Seriation (Chen) - blue",
col = hcl(h = 260, c = seq(75,0, length=10), l = seq(30,95, length=10)),
gp = gpar(fill = hcl(h = 260, c=30, l = 80)), newpage = FALSE))
popViewport()
pushViewport(viewport(layout.pos.row = 2, layout.pos.col = 2))
## supress average in lower triangle
plot(res, options = list(main = "PAM + Seriation (Chen) - no avg.",
average = FALSE, newpage = FALSE))
popViewport(2)
## the cluster_dissimilarity_matrix object
res
names(res)
Run the code above in your browser using DataLab