### 构造数据
library(ComplexHeatmap)
mat = matrix(rnorm(10000), 100)
colnames(mat) <- paste0("sample",1:100)
rownames(mat) <- paste0("gene",1:100)
head(mat)
### 注释样品分类信息
library(circlize)
col_fun = colorRamp2(c(-4, 0, 4), c("green", "white", "red"))
## 注意颜色映射
Heatmap(mat, name = "mat", col = col_fun)
ha = HeatmapAnnotation(
foo = c(1:40, NA, 42:100),
bar = c(NA, sample(letters[1:3], 99, replace = TRUE)),
col = list(foo = col_fun,
bar = c("a" = "red", "b" = "green", "c" = "blue")),
na_col = "black",
border=TRUE
)
# Heatmap(mat, name = "mat", top_annotation = ha)
# Heatmap(mat, name = "mat", top_annotation = ha,border=TRUE)
### 列不聚类,不改变样品顺序
Heatmap(mat, name = "mat", top_annotation = ha,
cluster_columns = FALSE,border=TRUE)
plot(ha) # 只作图样品聚类信息
2. ggplot实现
## not run
ggplot(data = m_data) +
geom_bar(mapping = aes(x = SAMPLE_ID, fill = SUBTYPE), # 改变填充颜色
position=position_dodge(1),width=1) +
scale_fill_manual(values = c("white","white","white","red"))
## end not run
### 不方便加外边框,颜色映射??