英文:
Changing Distance and Linkage of a heat map
问题
我正在尝试更改我的热图的距离和链接方式,从标准的欧几里德距离和完全链接到任何其他设置,以解决我的作业问题。
我们正在使用这个数据集:
library("flexclust")
data(milk)
help(milk)
这是我的当前代码:
hm3<-heatmap(milk_matrix, scale="column", main="哺乳动物乳汁组成的热图", xlab= "营养物质", ylab = "动物", cexRow = 0.6, cexCol = 1.1, col=heat.colors(10))
legend(x= "bottomright", legend=c("最小", "中间", "最大"), cex = 0.6, fill=heat.colors(3))
热图的R帮助文档中提到,你可以通过以下方式更改距离和链接方式:
distfun=
和
hclustfun=
但是我尝试过像hclustfun= "single"这样的输入,但没有成功。
任何帮助将不胜感激!只要不使用欧几里德距离和完全链接,我可以指定任何距离或链接方式。
亲切的问候,
Rosie
英文:
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
答案1
得分: 0
For the distfun
and hclustfun
arguments, you should use options already available in the stats::dist()
and stats::hclust()
functions (check their help). For example, to use the "maximum" distance measure instead of the default "euclidean" for distfun
, you can use the following:
# dist method must be one of "euclidean", "maximum", "manhattan", "canberra", "binary" or "minkowski"
heatmap(as.matrix(milk),
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),
distfun = function(x) dist(x, method = "maximum"))
legend(x= "bottomright", legend=c("min", "med", "max"), cex = 0.6, fill=heat.colors(3))
英文:
For the distfun
and hclustfun
arguments you have to use options already available in the stats::dist()
and stats::hclust()
(check their help). So for example for distfun
based on "maximum" distance measure instead of the default "euclidean" you can use the following:
# dist method must be one of "euclidean", "maximum", "manhattan", "canberra", "binary" or "minkowski"
heatmap(as.matrix(milk),
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),
distfun = function(x) dist(x, method = "maximum"))
legend(x= "bottomright", legend=c("min", "med", "max"), cex = 0.6, fill=heat.colors(3))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论