【问题标题】:New gplots update in R cannot find function distfun in heatmap.2R 中的新 gplots 更新在 heatmap.2 中找不到函数 distfun
【发布时间】:2013-11-19 14:33:53
【问题描述】:

我有一些 R 代码可以从相关矩阵制作热图,这在我上次使用它时有效(在 2013 年 10 月 17 日更新 gplots 之前;更新到 R 版本 3.0.2 之后)。这让我觉得在最近的 gplots 更新中发生了一些变化,但我不知道是什么。

以前呈现漂亮情节的东西现在给了我这个错误:

“hclustfun(distfun(x)) 中的错误:找不到函数“distfun”“

并且不会绘制任何东西。下面是重现该图的代码(在我使用它来教本科生如何在项目中使用热图时被大量评论)。我尝试添加最后一行以显式设置功能,但它无助于解决问题。

编辑:我将最后一行代码更改为: ,distfun =function(c) {as.dist(1-c,upper=FALSE)}, hclustfun=hclust) 它奏效了。当我只使用“dist=as.dist”时,我得到了一个图,但它没有正确排序,并且一些树状图分支没有连接到树。不知道发生了什么,也不知道为什么会这样,但似乎是这样。

任何帮助将不胜感激。

提前致谢,

library(gplots)
set.seed(12345)

randData <- as.data.frame(matrix(rnorm(600),ncol=6))

randDataCorrs <- randData+(rnorm(600))
names(randDataCorrs) <- paste(names(randDataCorrs),"_c",sep="")
randDataExtra <- cbind(randData,randDataCorrs)

randDataExtraMatrix <- cor(randDataExtra)


heatmap.2(randDataExtraMatrix, # sets the correlation matrix to use
          symm=TRUE, #tells whether it is symmetrical or not
          main= "Correlation matrix\nof Random Data Cor", # Names plot
          xlab= "x groups",ylab="", # Sets the x and y labels
          scale="none", # Tells it not to scale the data
          col=redblue(256),# Sets the colors (can be manual, see below) 
          trace="none", # tells it not to add a trace
          symkey=TRUE,symbreaks=TRUE, # Tells it to keep things symmetric around 0
          density.info = "none"#) # can be "histogram" if you want a hist of your corr values here
          #,distfun=dist, hclustfun=hclust)
          ,distfun =function(c) {as.dist(1-c,upper=FALSE)}, hclustfun=hclust) # new last line

【问题讨论】:

    标签: r


    【解决方案1】:

    我遇到了同样的错误,然后我注意到我创建了一个名为 dist 的变量,这是distfun= dist 的默认调用。 我重命名了变量,然后一切正常。您可能犯了同样的错误,因为您的新代码正在运行,因为您更改了 distfun 的默认调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-09
      • 2014-01-29
      • 2018-04-05
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多