對於一個簡單的二進制的配色方案,你可以使用breaks
參數:
library(pheatmap)
set.seed(1)
m1<-matrix(c(rnorm(1000)), ncol=100)
pheatmap(dist(t(m1)),
cluster_rows = F,
cluster_cols = F,
show_rownames = TRUE,
color = c("red", "black"),
breaks = c(0, 3, 9), # distances 0 to 3 are red, 3 to 9 black
main = 'Heatmap')
它看起來像這樣:
如果你喜歡的顏色漸變,這是可以做到的如下:
m <- matrix(c(rnorm(1000)), ncol=100)
distmat <- dist(t(m))
# Returns a vector of 'num.colors.in.palette'+1 colors. The first 'cutoff.fraction'
# fraction of the palette interpolates between colors[1] and colors[2], the remainder
# between colors[3] and colors[4]. 'num.colors.in.palette' must be sufficiently large
# to get smooth color gradients.
makeColorRampPalette <- function(colors, cutoff.fraction, num.colors.in.palette)
{
stopifnot(length(colors) == 4)
ramp1 <- colorRampPalette(colors[1:2])(num.colors.in.palette * cutoff.fraction)
ramp2 <- colorRampPalette(colors[3:4])(num.colors.in.palette * (1 - cutoff.fraction))
return(c(ramp1, ramp2))
}
cutoff.distance <- 3
cols <- makeColorRampPalette(c("white", "red", # distances 0 to 3 colored from white to red
"green", "black"), # distances 3 to max(distmat) colored from green to black
cutoff.distance/max(distmat),
100)
pheatmap(distmat,
cluster_rows = F,
cluster_cols = F,
show_rownames = TRUE,
color = cols,
main = 'Heatmap')
然後看起來裏柯本:
嗨@WhiteViking,我想這和它處理了半個多小時,直到我停止它。我正在與Rstudio在McBook 1,4 GHz Intel Core i5上合作。另外,對我來說,在黑色背景中只有紅點是不錯的。 – Kwnwps
@Kwnwps我已經添加了一個使用二進制配色方案的示例(紅色黑點)。 – WhiteViking
@Kwnwps至於處理時間很長:這個玩具的例子會發生嗎?或者只爲一個更大的數據集 - 如果是這樣的話? – WhiteViking