# Create matrix
y <- matrix(rnorm(50), 10, 5,
dimnames = list(paste("g",1:10,sep=""),
paste("t",1:5,sep="")))
# Correlation matrix
c <- cor(t(y), method="spearman")
# Convert to distance
d <- [Link](1-c)
# Hierarchical clustering
hr <- hclust(d, method="complete")
# Plot area
par(mfrow=c(2,2))
# Dendrogram plots
plot(hr, hang=0.1)
plot(hr, hang=-1)
plot([Link](hr),
edgePar=list(col=3,lwd=2),
horiz=TRUE)
# Clustering details
unclass(hr)
str([Link](hr))
hr$labels[hr$order]
# Convert to dendrogram
hrd1 <- [Link](hr)
plot(hrd1)
# Reorder dendrogram
[Link](1)
hrd2 <- reorder(hrd1, sample(1:10))
plot(hrd2)
# Labels
labels(hrd1)
labels(hrd2)
# Example with mtcars dataset
d <- dist([Link](mtcars))
hc <- hclust(d)
plot(hc)
# Draw clusters
[Link](hc, k=3, border="red")
# Generate data
[Link](1)
y <- matrix(rnorm(50),10,5,
dimnames=list(paste("g",1:10,sep=""),
paste("t",1:5,sep="")))
# Correlation
c <- cor(t(y),method="spearman")
# Distance matrix
d <- [Link](1-c)
# Hierarchical clustering
hr <- hclust(d,method="complete")
# Plot layout
par(mfrow=c(2,2))
# Dendrogram plots
plot(hr,hang=0.1)
plot(hr,hang=-1)
plot([Link](hr),
edgePar=list(col=3,lwd=2),
horiz=TRUE)
# Clustering details
unclass(hr)
# Structure
str([Link](hr))
# Order labels
hr$labels[hr$order]
# Convert to dendrogram
hrd1 <- [Link](hr)
plot(hrd1)
# Reorder dendrogram
hrd2 <- reorder(hrd1,sample(1:10))
plot(hrd2)
# Labels
labels(hrd1)
labels(hrd2)
# Example using mtcars dataset
d <- dist([Link](mtcars))
hc <- hclust(d)
plot(hc)
[Link](hc,k=3,border="red")