热图合并 R 中合并图的公共行

Heatmap merging common rows for a consolidated plot in R

我正在使用 ggvis 使用以下示例数据创建热图 (plot1)。

Class Super_class   cell1   cell2   cell3
A1      A             2      3.96   0.6
A2      A             1      2.92   0
A3      A             5      0.56   6.4
A4      A             1      10.92  22.36
A5      A             0        0    5.32
B       B             0        0    1
C1      C             0.64     2.4  3.4
C2      C             0       3.6   2.56
C3      C             0.6      2     2
C4      C             1.96     1    9.96
C5      C             4.6    17.56   10

但是由于 Class 可以分类为 super 类 as A , B , C - 我想做一个合并的图,它具有与 plot1 相同的信息,但具有颜色叠加以提供更多密度(plot2)。

在我试过的情节中,他们似乎不一样;由于在 A4、cell3 (plot1) 中看到的高强度未反映在 plot2 中(对于 A、cell3)

任何建议都会有很大帮助

这是我正在使用的代码

dfm = melt(df)
sample <- dfm %>% 
  ggvis(~factor(variable), ~factor(Class), fill=~value) %>%
  layer_rects(width = band(), height = band(), strokeWidth := 0) %>%
  scale_nominal("x", padding = 0) %>%
  scale_nominal("y", padding = 0) %>%
  scale_numeric("fill", range=c("white", "red")) %>%
  add_legend("fill", title = "Score") %>%
  add_axis("x", orient='top',title = "Sample",properties=axis_props(labels = list(angle=70, fontSize=12))) %>%
  add_axis("y",orient='right', title = "Class")

我不清楚你想要达到什么目的,但据我了解:

library(ggvis)
library(tidyr)
library(dplyr)

df %>% 
  gather(variable, value, -Class, -Super_class) %>%
  group_by(Super_class, variable) %>%
  summarise(value = sum(value)) %>%
  mutate_each(funs(factor), -value) %>%
  ggvis(~variable, ~Super_class, fill=~value) %>%
  layer_rects(width = band(), height = band(), strokeWidth := 0) %>%
  layer_text(
    x = prop("x", ~variable, scale = "xcenter"),
    y = prop("y", ~Super_class, scale = "ycenter"),
    text:=~value, fontSize := 14, fill:="black", 
    baseline:="middle", align:="center") %>%
  scale_nominal("x", padding = 0) %>%
  scale_nominal("y", padding = 0) %>%
  scale_nominal("x", name = "xcenter", padding = 1, points = TRUE) %>%
  scale_nominal("y", name = "ycenter", padding = 1, points = TRUE) %>%
  scale_numeric("fill", range=c("white", "red")) %>%
  add_legend("fill", title = "Score") %>%
  add_axis("x", orient = 'top', title = "Sample") %>%
  add_axis("y", orient = 'right', title = "Class")

给出: