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
library("grid")
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
## color: use 10 shades of blue (hue = 270)
plot(res, options = list(main = "PAM + Seriation (Chen) - blue, only avg.",
col= 10, hue=260, averages = c(TRUE, TRUE), newpage = FALSE))
popViewport()
pushViewport(viewport(layout.pos.row = 2, layout.pos.col = 1))
## threshold and cubic scale to highlight differences
plot(res, options = list(main = "PAM + Seriation (Chen) - threshold",
threshold = 1.5, power = 3, newpage = FALSE))
popViewport()
pushViewport(viewport(layout.pos.row = 2, layout.pos.col = 2))
## use custom (logistic) scale
plot(res, options = list(main = "PAM + Seriation (Chen) - logistic scale",
col= hcl(c = 0, l = (plogis(seq(0,10,length=100),
location = 2, scale = 1/2, log = FALSE))*100),
newpage = FALSE))
popViewport(2)
## the reordered_cluster_dissimilarity_matrix object
res
names(res)
Run the code above in your browser using DataLab