3

次のコードがありますが、それを使用して、定義された値を表す 5 つの異なる色を表示するカラー キーでヒートマップを表示する方法がわかりません。

hm <- heatmap.2(data_matrix, scale="none",Rowv=NA,Colv=NA,col = rev(brewer.pal(11,"RdBu")),margins=c(5,5),cexRow=0.5, cexCol=1.0,key=TRUE,keysize=1.5, trace="none")

必要なカラー キー:

<0.3 (blue)

0.3-1 (green)

1-1.3 (yellow)

1.3-3.0 (orange)

>3.0 (red)

誰かの役に立てば幸いです。ありがとう!

ジェームズ

4

1 に答える 1

8
require(gplots)
require(RColorBrewer)

## Some fake data for you
data_matrix <- matrix(runif(100, 0, 3.5), 10, 10)

## The colors you specified.
myCol <- c("blue", "green", "yellow", "orange", "red")
## Defining breaks for the color scale
myBreaks <- c(0, .3, 1, 1.3, 3, 3.5)

hm <- heatmap.2(data_matrix, scale="none", Rowv=NA, Colv=NA,
                col = myCol, ## using your colors
                breaks = myBreaks, ## using your breaks
                dendrogram = "none",  ## to suppress warnings
                margins=c(5,5), cexRow=0.5, cexCol=1.0, key=TRUE, keysize=1.5,
                trace="none")

これは機能するはずであり、必要に応じてさらに編集する方法についていくつかのアイデアが得られます。正確な値で凡例を取得するには、組み込みのヒストグラムを気にせず、代わりに次を使用しますlegend

hm <- heatmap.2(data_matrix, scale="none", Rowv=NA, Colv=NA,
                col = myCol, ## using your colors
                breaks = myBreaks, ## using your breaks
                dendrogram = "none",  ## to suppress warnings
                margins=c(5,5), cexRow=0.5, cexCol=1.0, key=FALSE,
                trace="none")
legend("left", fill = myCol,
    legend = c("0 to .3", "0.3 to 1", "1 to 1.3", "1.3 to 3", ">3"))
于 2012-07-29T23:06:03.607 に答える