Saturday, April 6, 2013

RG#16: plot dendogram and phylogenic trees of different types


# data 
set.seed(1234)
 P <- vector()
DF <- as.data.frame(matrix(rep(NA, 100), nrow=10))
names(DF) <- c(paste("M",1:10, sep=""))
for(i in 1:10) {
                    DF[,i] <- rnorm(10, 10, 3)
                    }
rownames (DF) <- paste("O", 1:10, sep = "")


# Data analysis
 HC.1 <- hclust(dist(model.matrix(~-1 + M1+M2+M3+M4+M5+M7+M7+M8+M9+M10,
data = DF)), method= "ward")
# plot the dendogram
plot(HC.1, main= "Cluster Dendrogram for Solution HC.1", xlab= "Observation Number in Data Set DF", sub="Method=ward; Distance=euclidian")



#Now you can convert the dendogram to different types of phylogy objects 
# need ape package 
require(ape)
pobj <- as.phylo(HC.1) # convert to phylog object
#Let’s plot all possible types of trees from this dendogram output
 par(mfrow = c(2,3))
plot(pobj, type = "c" )# "cladogram"
title (main = "cladogram")

plot(pobj, type = "u")# "unrooted"
title (main =  "unrooted")

plot(pobj, type = "f")# "fan"
title (main =  "fan")

plot(pobj, type = "r")#"radial"
title (main =  "radial")

plot(pobj, type = "p")# "phylogram"
title (main = "phylogram")


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.