I am trying to change the distance and linkage of my heat map from the standard Euclidean Distance and Complete linkage to any other setting for a question in my homework.
We are using this data set:
library("flexclust")
data(milk)
help(milk)
this is my current code:
hm3<-heatmap(milk_matrix, scale="column", main="Heat map of the Composition of Mammals' Milk", xlab= "Nutrient", ylab = "Animal", cexRow = 0.6, cexCol = 1.1, col=heat.colors(10))
legend(x= "bottomright", legend=c("min", "med", "max"), cex = 0.6, fill=heat.colors(3))
R help for heat map says you can change the distance/ linkage by:
distfun= and hclustfun=
but I have had no luck typing something such as hclustfun= "single".
Any help would be greatly appreciated ! I can specify any distance or linkage as long as it is not Euclidean Distance and Complete linkage.
Kind Regards, Rosie :)
heat map changing distance and linkage
For the
distfunandhclustfunarguments you have to use options already available in thestats::dist()andstats::hclust()(check their help). So for example fordistfunbased on "maximum" distance measure instead of the default "euclidean" you can use the following: