修改热图的距离和链接方式

huangapple go评论54阅读模式
英文:

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(&quot;flexclust&quot;)
data(milk)
help(milk)

this is my current code:

hm3&lt;-heatmap(milk_matrix, scale=&quot;column&quot;, main=&quot;Heat map of the Composition of Mammals&#39; Milk&quot;, xlab= &quot;Nutrient&quot;, ylab = &quot;Animal&quot;, cexRow = 0.6, cexCol = 1.1, col=heat.colors(10))
legend(x= &quot;bottomright&quot;, legend=c(&quot;min&quot;, &quot;med&quot;, &quot;max&quot;),  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 &quot;euclidean&quot;, &quot;maximum&quot;, &quot;manhattan&quot;, &quot;canberra&quot;, &quot;binary&quot; or &quot;minkowski&quot;

heatmap(as.matrix(milk), 
        scale=&quot;column&quot;, 
        main=&quot;Heat map of the Composition of Mammals&#39; Milk&quot;, 
        xlab= &quot;Nutrient&quot;, 
        ylab = &quot;Animal&quot;, 
        cexRow = 0.6, 
        cexCol = 1.1, 
        col=heat.colors(10),
        distfun = function(x) dist(x, method = &quot;maximum&quot;))
legend(x= &quot;bottomright&quot;, legend=c(&quot;min&quot;, &quot;med&quot;, &quot;max&quot;),  cex = 0.6, fill=heat.colors(3))

huangapple
  • 本文由 发表于 2023年5月21日 18:35:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76299443.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定