Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created November 20, 2025 06:37
Show Gist options
  • Select an option

  • Save abikoushi/25561ac08b10f8f1e285019bafb81295 to your computer and use it in GitHub Desktop.

Select an option

Save abikoushi/25561ac08b10f8f1e285019bafb81295 to your computer and use it in GitHub Desktop.
Try ComplexHeatmap
#BiocManager::install("ComplexHeatmap")
library(tidyr)
library(dplyr)
library(tibble)
library(ComplexHeatmap)
df0 <- rownames_to_column(mtcars, var="car") %>%
separate(car, into=c("name","model"), extra="merge")
head(df0)
row_ha <- rowAnnotation(
dummy = anno_simple(
rep(LETTERS[1:2],16),,
col = structure(hcl.colors(2),
names = LETTERS[1:2]),
border = TRUE))
# 行 split 用ベクトル
row_split <- df0$name
names(row_split) <- rownames(mtcars)
MM = log1p(as.matrix(df0[,-c(1:2)]))
rownames(MM) = rownames(mtcars)
HM=Heatmap(
MM,
name = "value",
cluster_columns = TRUE,
cluster_rows = FALSE,
clustering_method_columns = "ward.D",
row_split = row_split,
show_row_names = TRUE,
show_column_names = TRUE,
row_title_rot = 0,
right_annotation = row_ha
)
png("heatmap.png", width = 600, height = 600)
draw(HM)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment