我是 R 新手。我想创建一个圆形热图并根据 https://jokergoo.github.io/2020/05/21/make-circular-heatmaps/ 设置一些分割,其中表示:
如果 split 参数的值是一个因子,则因子级别的顺序控制热图的顺序。如果 split 是一个简单向量,则热图的顺序是唯一的(split)。
# note since circos.clear() was called in the previous plot,
# now the layout starts from theta = 0 (the first sector is 'e')
circos.heatmap(mat1, split = factor(split, levels = c("e", "d", "c", "b", "a")),
col = col_fun1, show.sector.labels = TRUE)
library(circlize)
library(ComplexHeatmap)
library(dendextend)
mat1=read.csv("esters.csv")
row.names(mat1)<-mat1[,1]#
mat2<-mat1[,-1]##remove the first column
mat3<-mat1[-1,]##remove the first row
#Draw circoheatmap
col_fun1 = colorRamp2(c(0, 0.00001, 0.0001, 0.001, 0.01,0.1, 0.4, 0.8), c("#FAFAFA", "#EAF7E7", "#E0F3DC", "#D7F0D1", "#CDEBC6", "#D5E4FD", "#8CACE3", "#5E7192"))##
circos.par(start.degree = 90, gap.degree = 10, gap.after = c(10))##
mat1 = mat1[sample(165, 165), ] # randomly permute rows
split = sample(letters[1:5], 165, replace = TRUE)
splits = factor(split, levels = letters[1:5])
circos.heatmap(mat2, col = col_fun1, split = splits,
dend.track.height = 0.15,
dend.side = "inside",
rownames.side = "outside",
dend.callback = function(dend, m, si) {
color_branches(dend, k = 4, col = 1:4)
}
)
#By default, the numeric matrix is clustered on rows.
#Used to draw legend
lgd = Legend(title = "Relative abundance", col_fun = col_fun1)
grid.draw(lgd)
circos.clear()
我尽力去理解它,但还是不行。 有谁能告诉我应该输入什么吗
split = ???
在我的代码中我是这样解决的。 我只是创建了一个因子变量,因此用您的代码制作一个简化的示例...假设“ester1”、“ester2”、“ester3”是“group1”,而“ester4”、“ester5”、“ester6” ” 是“group2”。 假设
的输出rownames(mat1)
退货
"ester1", "ester2", "ester3", "ester4", "ester5", "ester6"
首先你需要创建一个这样的列表
levels <- c("group1","group1","group1","group2","group2","group2")
使得
rownames
中的每个酯位置与其在 levels
向量中的基团之间存在对应关系。
那么简单
split=factor(levels)
现在您可以在
split
函数中使用这个 circos.heatmap
变量。