相関行列からヒートマップを作成するための 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