目录
1:rowAnnotation展示行注释
不过这个参数好像不太方便设置颜色
rm(list = ls())
library(ComplexHeatmap)
library(circlize)
library(cowplot)
# 只有一个注释则必须额外加上NULL
p1 <- rowAnnotation(bar = anno_barplot(1:12, width = unit(4, "cm"))) + NULL
p1
p2 <- rowAnnotation(foo = 1:12) +
rowAnnotation(bar = anno_barplot(1:12, width = unit(4, "cm")))
p2
draw(p1+p2)
# 同样可以使用draw里面的功能进行操作
anno_list = rowAnnotation(foo = 1:12) +
rowAnnotation(bar = anno_barplot(1:12, width = unit(4, "cm")))
p3 <- draw(anno_list, row_split = rep(c("A", "B"), each = 6))
2:HeatmapAnnotation展示列注释
https://jokergoo.github.io/ComplexHeatmap-reference/book/other-high-level-plots.html
rm(list = ls())
library(ComplexHeatmap)
library(circlize)
prop = c(
runif(10, min = 0.1, max = 0.5),
runif(10, min = 0.2, max = 0.4),
runif(10, min = 0.3, max = 0.6),
runif(10, min = 0.4, max = 0.8)
)
median_length = c(
runif(10, min = 5000, max = 10000),
runif(10, min = 6000, max = 20000),
runif(10, min = 7000, max = 15000),
runif(10, min = 6000, max = 30000)
)
group = rep(letters[1:4], each = 10)
#进行绘图#
ht_list = HeatmapAnnotation(prop = anno_barplot(prop, height = unit(4, "cm"),
axis_param = list(at = c(0, 0.2, 0.4, 0.6, 0.8),
labels = c("0%", "20%", "40%", "60%", "80%"))),
annotation_name_rot = 90) %v%
HeatmapAnnotation(median_length = anno_barplot(median_length, height = unit(4, "cm"),
axis_param = list(at = c(0, 10000, 20000), labels = c("0kb", "10kb", "20kb"))),
annotation_name_rot = 90) %v%
HeatmapAnnotation(group = group)
draw(ht_list, column_title = "Statistics for a list of genomic regions")
注释数据
3:进行排序和颜色设置
rm(list = ls())
library(ComplexHeatmap)
library(circlize)
prop = c(
runif(10, min = 0.1, max = 0.5),
runif(10, min = 0.2, max = 0.4),
runif(10, min = 0.3, max = 0.6),
runif(10, min = 0.4, max = 0.8)
)
median_length = c(
runif(10, min = 5000, max = 10000),
runif(10, min = 6000, max = 20000),
runif(10, min = 7000, max = 15000),
runif(10, min = 6000, max = 30000)
)
group = rep(letters[1:4], each = 10)
#进行排序和颜色升级设置(刚好数据包含了连续变量和分类变量)
dat <- data.frame(prop,
median_length,
group)
dat1 <- dat[order(dat$prop,dat$median_length),]##进行排序
head(dat1) prop median_length group 6 0.1232123 5362.346 a 9 0.1471081 5747.062 a 5 0.1553561 5593.452 a 2 0.1771223 6036.827 a 1 0.1808738 6879.217 a 4 0.2254072 6207.511 a
ht_list = HeatmapAnnotation(prop = anno_barplot(dat1$prop, height = unit(4, "cm"),
#gp = gpar(fill = 9),
axis_param = list(at = c(0, 0.2, 0.4, 0.6, 0.8),
labels = c("0%", "20%", "40%", "60%", "80%"))),
annotation_name_rot = 90) %v%
#%v% 进行垂直连接:一个为柱状图,一个为散点图
HeatmapAnnotation(median_length = anno_points(dat1$median_length, height = unit(4, "cm"),
axis_param = list(at = c(0, 10000, 20000), labels = c("0kb", "10kb", "20kb"))),
annotation_name_rot = 90) %v%
HeatmapAnnotation(group = dat1$group,
col = list(group = c("a" = "red", "b" = "#1f78b4", "c" = "white","d"="#ff7f00")))#分类变量的颜色设置
#绘图
draw(ht_list, column_title = "Statistics for a list of genomic regions")
dev.off()
4:进一步设置基线美化
ht_list = HeatmapAnnotation(prop = anno_barplot(dat1$prop, height = unit(4, "cm"),
gp = gpar(fill = ifelse(dat1$prop > 0.5, "red", "blue")),
baseline = 0.5,
axis_param = list(at = c(0, 0.2, 0.4, 0.6, 0.8),
labels = c("0%", "20%", "40%", "60%", "80%"))),
annotation_name_rot = 90) %v%
#%v% 进行垂直连接:一个为柱状图,一个为散点图
HeatmapAnnotation(median_length = anno_points(dat1$median_length, height = unit(4, "cm"),
gp = gpar(col = 2),
axis_param = list(at = c(0, 10000, 20000), labels = c("0kb", "10kb", "20kb"))),
annotation_name_rot = 90) %v%
HeatmapAnnotation(group = dat1$group,
col = list(group = c("a" = "red", "b" = "#1f78b4", "c" = "white","d"="#ff7f00")))#分类变量的颜色设置
#绘图
draw(ht_list, column_title = "Statistics for a list of genomic regions")
dev.off()
参考:https://jokergoo.github.io/ComplexHeatmap-reference/book/a-list-of-heatmaps.html