我要订购4个热图的复合热图,这些热图由包含在基础数据集的“订单”列中的行顺序连接在一起,但是我不希望最终图形中的订单列/数据可见。 实际上,我希望这些行从上到下与该数据示例相同,即G,Y,K,Z,P,L,V,B,W,O,S,R,X,T(从上到下) ), 但是,当我运行代码时,行顺序更改为(从上到下) T,K,Z,G,L,V,B,P,Y,S,R,X,O
这是数据-
名称,#V,#O,#I,#S,#R,#E,%W,Order
G,348,0,287,371,392,304,75.522727,1
Y,140,0,85,144,180,103,75.886364,2
K,256,0,197,273,300,214,79.068182,5
Z,225,80,166,238,269,183,80.454545,6
P,174,0,113,183,218,132,82.136364,7
L,170,0,108,176,213,129,75.522727,8
V,170,20,108,176,213,129,80.272727,9
B,167,0,106,171,210,127,3.818182,10
W,167,90,106,171,210,127,100,12
O,12,0,79,12,54,39,80.5,13
S,6,30,77,6,48,35,59.5,14
R,6,0,79,6,49,36,80.454545,15
X,2,50,73,2,45,32,59.772727,19
T,268,0,207,281,311,227,80.522727,20
这是代码-
library("ComplexHeatmap", lib.loc="C:/Users/q805269/Documents/R/R-3.5.1/library")
library("RColorBrewer", lib.loc="C:/Users/q805269/Documents/R/R-3.5.1/library")
library("circlize", lib.loc="C:/Users/q805269/Documents/R/R-3.5.1/library")
library("crayon", lib.loc="C:/Users/q805269/Documents/R/R-3.5.1/library")
library("pillar", lib.loc="C:/Users/q805269/Documents/R/R-3.5.1/library")
library("dplyr", lib.loc="C:/Users/q805269/Documents/R/R-3.5.1/library")
colnames(dataset)[1] <- c("Name")
row.names(dataset) <- dataset$"Name"
merged<-dataset
merged1<-select(merged, "# I","# S","# R","# E")
max_merged1<-as.numeric(max(merged1$"# I"))
max_merged2<-as.numeric(max(merged1$"# S"))
max_merged3<-as.numeric(max(merged1$"# R"))
max_merged4<-as.numeric(max(merged1$"# E"))
max_merged<-as.numeric(max(max_merged2, max_merged1, max_merged3, max_merged4))
rc3<-max_merged==0
if(rc3 == "TRUE") max_merged<-10 else max_merged
mergedvc<-select(merged, "# V")
max_mergedvc<-as.numeric(max(mergedvc$"# V"))
rc2<-max_mergedvc==0
if(rc2 == "TRUE") max_mergedvc<-10 else max_mergedvc
mergedwst <- select(merged, "% W")
max_mergedwst <- as.numeric(max(mergedwst$"% W"))
rc1 <- max_mergedwst==0
if(rc1 == "TRUE") max_mergedwst<-10 else max_mergedwst
mergedord<-select(merged, "# O")
max_mergedord<-as.numeric(max(mergedord$"# O"))
rc<-max_mergedord==0
if(rc == "TRUE") max_mergedord<-10 else max_mergedord
merged2<-as.matrix(merged1)
mergedvc2<-as.matrix(mergedvc)
mergedwst2<-as.matrix(mergedwst)
mergedord2<-as.matrix(mergedord)
ht_global_opt(heatmap_legend_title_gp = gpar(fontsize = 6, fontface = "bold"),
heatmap_legend_labels_gp = gpar(fontsize = 6), heatmap_column_names_gp = gpar(fontsize = 6))
ht1<-Heatmap(merged2,
show_row_dend = FALSE,
show_column_dend = FALSE,
show_row_names = FALSE,
column_names_side = "top",
column_names_gp = gpar(fontsize = 8),
name = "# I,# E,# S,# R",
cell_fun = function(j, i, x, y, width, height, fill)
{
grid.text(sprintf("%.0f", merged2[i, j]), x, y, gp = gpar(fontsize = 8))
},
col = colorRamp2(c(0, max_merged), c(rgb(200/255, 202/255, 201/255),rgb(116/255, 122/255, 119/255))))
ht2<-Heatmap(mergedvc2,
show_row_dend = FALSE,
show_column_dend = FALSE,
row_names_side = "left",
column_names_side = "top",
column_names_gp = gpar(fontsize = 8),
row_names_gp = gpar(fontsize = 8),
name = "# V",
cell_fun = function(j, i, x, y, width, height, fill)
{
grid.text(sprintf("%.0f", mergedvc2[i, j]), x, y,
gp = gpar(fontsize = 8))
},
col = colorRamp2(c(0, max_mergedvc),
c(rgb(185/255, 221/255, 141/255),
rgb(119/255, 188/255, 31/255))))
ht3<-Heatmap(mergedwst2,
show_row_dend = FALSE,
show_column_dend = FALSE,
show_row_names = FALSE,
column_names_side = "top",
column_names_gp = gpar(fontsize = 8),
name = "% W", cell_fun = function(j, i, x, y, width, height, fill)
{
grid.text(sprintf("%.0f", mergedwst2[i, j]), x, y, gp = gpar(fontsize = 8))
},
col = colorRamp2(c(0,max_mergedwst), c( rgb(236/255, 154/255, 169/255),rgb(217/255, 59/255, 86/255))))
ht4<-Heatmap(mergedord2,
show_row_dend = FALSE,
show_column_dend = FALSE,
show_row_names = FALSE,
column_names_side = "top",
column_names_gp = gpar(fontsize = 8),
name = "# O", cell_fun = function(j, i, x, y, width, height, fill) {
grid.text(sprintf("%.0f", mergedord2[i, j]), x, y,
gp = gpar(fontsize = 8))
},
col = colorRamp2(c(0,max_mergedord),
c(rgb(255/255, 207/255, 176/255),
rgb(255/255, 108/255, 12/255))))
ht_list<-ht2+ht4+ht1+ht3
draw(ht_list, gap = unit(0, "cm"))
答案 0 :(得分:1)
Got it!
基本添加
cluster_rows = FALSE,
cluster_columns = FALSE,
colnames(dataset)[1] <- c("Name")
row.names(dataset) <- dataset$"Name"
merged<-dataset
merged1<-select(merged, "# I","# S","# R","# E")
max_merged1<-as.numeric(max(merged1$"# I"))
max_merged2<-as.numeric(max(merged1$"# S"))
max_merged3<-as.numeric(max(merged1$"# R"))
max_merged4<-as.numeric(max(merged1$"# E"))
max_merged<-as.numeric(max(max_merged2,max_merged1,max_merged3,max_merged4))
rc3<-max_merged==0
if(rc3 == "TRUE") max_merged<-10 else max_merged
mergedvc<-select(merged, "# V")
max_mergedvc<-as.numeric(max(mergedvc$"# V"))
rc2<-max_mergedvc==0
if(rc2 == "TRUE") max_mergedvc<-10 else max_mergedvc
mergedwst<-select(merged, "% W")
max_mergedwst<-as.numeric(max(mergedwst$"% W"))
rc1<-max_mergedwst==0
if(rc1 == "TRUE") max_mergedwst<-10 else max_mergedwst
mergedord<-select(merged, "# O")
max_mergedord<-as.numeric(max(mergedord$"# O"))
rc<-max_mergedord==0
if(rc == "TRUE") max_mergedord<-10 else max_mergedord
merged2<-as.matrix(merged1)
mergedvc2<-as.matrix(mergedvc)
mergedwst2<-as.matrix(mergedwst)
mergedord2<-as.matrix(mergedord)
ht_global_opt(heatmap_legend_title_gp = gpar(fontsize = 6, fontface = "bold"),
heatmap_legend_labels_gp = gpar(fontsize = 6), heatmap_column_names_gp = gpar(fontsize = 6))
ht1<-Heatmap(merged2,
show_row_dend = FALSE,
show_column_dend = FALSE,
show_row_names = FALSE,
column_names_side = "top",
column_names_gp = gpar(fontsize = 8),
cluster_rows = FALSE,
cluster_columns = FALSE,
name = "# I,# E,# S,# R", cell_fun = function(j, i, x, y, width, height, fill)
{
grid.text(sprintf("%.0f", merged2[i, j]), x, y, gp = gpar(fontsize = 8))
},
col = colorRamp2(c(0, max_merged), c(rgb(200/255, 202/255, 201/255),rgb(116/255, 122/255, 119/255))))
ht2<-Heatmap(mergedvc2,
show_row_dend = FALSE,
show_column_dend = FALSE,
row_names_side = "left",
column_names_side = "top",
column_names_gp = gpar(fontsize = 8),
row_names_gp = gpar(fontsize = 8),
cluster_rows = FALSE,
cluster_columns = FALSE,
name = "# V", cell_fun = function(j, i, x, y, width, height, fill)
{
grid.text(sprintf("%.0f", mergedvc2[i, j]), x, y, gp = gpar(fontsize = 8))
},
col = colorRamp2(c(0, max_mergedvc), c(rgb(185/255, 221/255, 141/255),rgb(119/255, 188/255, 31/255))))
ht3<-Heatmap(mergedwst2,
show_row_dend = FALSE,
show_column_dend = FALSE,
show_row_names = FALSE,
column_names_side = "top",
column_names_gp = gpar(fontsize = 8),
uster_rows = FALSE,
uster_columns = FALSE,
name = "% W", cell_fun = function(j, i, x, y, width, height, fill)
{
grid.text(sprintf("%.0f", mergedwst2[i, j]), x, y, gp = gpar(fontsize = 8))
},
col = colorRamp2(c(0,max_mergedwst), c( rgb(236/255, 154/255, 169/255),rgb(217/255, 59/255, 86/255))))
ht4<-Heatmap(mergedord2,
show_row_dend = FALSE,
show_column_dend = FALSE,
show_row_names = FALSE,
column_names_side = "top",
column_names_gp = gpar(fontsize = 8),
uster_rows = FALSE,
uster_columns = FALSE,
name = "# O", cell_fun = function(j, i, x, y, width, height, fill)
{
grid.text(sprintf("%.0f", mergedord2[i, j]), x, y, gp = gpar(fontsize = 8))
},
col = colorRamp2(c(0,max_mergedord), c( rgb(255/255, 207/255, 176/255),rgb(255/255, 108/255, 12/255))))
ht_list<-ht2+ht4+ht1+ht3
draw(ht_list, gap = unit(0, "cm"))