如何从R pheatmap获取色阶值(行z得分值)

时间:2018-03-28 03:40:59

标签: r heatmap pheatmap

我有以下数据框:

library(pheatmap)
library(RColorBrewer)

dat <- structure(c(36.28516213, -9.184523335, 5.716034994, 32.82180488, 
-18.5467127, 22.79930301, -24.79075287, -49.23768715), .Dim = c(2L, 
4L), .Dimnames = list(c("motif_a", "motif_b"), c("cow", "dog", 
"snake", "cat")))

dat
#>               cow       dog     snake       cat
#> motif_a 36.285162  5.716035 -18.54671 -24.79075
#> motif_b -9.184523 32.821805  22.79930 -49.23769

使用以下热图代码:

p <- pheatmap(
  dat,
  color = colorRampPalette(rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu")))(1000),
  clustering_method = "ward.D2",
  border_color = "grey60",
  clustering_distance_columns = "correlation",
  clustering_distance_rows = "correlation",
  fontsize_row = 6,
  cluster_rows = TRUE,
  cluster_cols = TRUE,
  scale = "row"
)

我可以得到这个情节。

enter image description here

如图中所示,我如何获得相应的值 热图中的每个点都是右手的色标。

例如,cow motif_b的值为-9.184523,但右侧为{ "device_id_type": "aaid", "device_id": "BAC9BA51-4C51-45C8-8091-3F6890A21A70", "app_version": "1.1", "country": "US", "q": "hello", "offset": 0, "limit": 20, "locale": "en_US", "tz_offset": -5, "gender": "m", "age": "21-24", "geo": "40.7506, 73.9935" } 色标的值介于0到-0.5之间。我怎样才能得到这些值?

最终结果是具有转换值的数据框。 我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

当您指定pheatmap时,您要求clustering_distance_xxx = "correlation"绘制Pearson相关性,该相关性介于-1和1之间。运行?pheatmap了解更多详情。

如果您从代码中删除这些部分,那么您将获得预期

library(pheatmap)
library(RColorBrewer)

dat <- structure(c(36.28516213, -9.184523335, 5.716034994, 32.82180488, 
    -18.5467127, 22.79930301, -24.79075287, -49.23768715), .Dim = c(2L, 
    4L), .Dimnames = list(c("motif_a", "motif_b"), c("cow", "dog", 
    "snake", "cat")))

myCol <- colorRampPalette(rev(RColorBrewer::brewer.pal(n = 7, name = "RdYlBu")))(8)

p <- pheatmap(
  dat,
  color = myCol,
  clustering_method = "ward.D2",
  border_color = "grey60",
  clustering_distance_columns = "correlation",
  clustering_distance_rows = "correlation",
  fontsize_row = 6,
  cluster_rows = TRUE,
  cluster_cols = TRUE,
  scale = "row"
)

p1 <- pheatmap(
  dat,
  color = myCol,
  clustering_method = "ward.D2",
  border_color = "grey60"
)

reprex package(v0.2.0)创建于2018-03-27。