前面我们在人工智能大模型不会告诉你的热图绘制技巧 演示了如何使用ggplot2热图扩展包(ggalign),可以快速替代之前的 pheatmap:
实际上这个ggplot2热图扩展包(ggalign)的功能不仅于此,还可以绘制肿瘤外显子的常见的图表:瀑布图
安装
前面我们在人工智能大模型不会告诉你的热图绘制技巧 演示了如何使用ggplot2热图扩展包(ggalign),可以快速替代之前的 pheatmap:
实际上这个ggplot2热图扩展包(ggalign)的功能不仅于此,还可以绘制肿瘤外显子的常见的图表:瀑布图
你可以使用以下命令从 CRAN
安装 ggalign
:
install.packages("ggalign")
或者,从 r-universe[1] 安装开发版本(目前开发版本添加了大量新功能,因为CRAN通常需要1-2个月的更新间隔,暂不能推送到CRAN):
install.packages("ggalign",
repos = c("https://yunuuuu.r-universe.dev", "https://cloud.r-project.org")
)
或者从GitHub[2]
# install.packages("remotes")
remotes::install_github("Yunuuuu/ggalign")
如果您在使用ggalign后觉得它对您的工作有所帮助,欢迎在 https://github.com/Yunuuuu/ggalign
上为此项目添加星星。
输入数据
ggoncoplot
接受一个字符矩阵,用于编码突变类型,您可以使用;:,|
来分隔多个突
变,或者任何定义了fortify_heatmap()
方法的对象。目前能直接接受maftools
的对象。
mat <- read.table(textConnection(
"s1,s2,s3
g1,snv; indel,snv,indel
g2,,snv;indel,snv
g3,snv,,indel;snv"
), row.names = 1, header = TRUE, sep = ",", stringsAsFactors = FALSE)
所有操作跟ggheatmap()
一摸一样,想要更多文档?请参考:https://yunuuuu.github.io/ggalign/dev/
ggoncoplot(mat, map_width = c(snv = 0.5), map_height = c(indel = 0.9)) +
# Note that guide legends from `geom_tile` and `geom_bar` are different.
# Although they appear similar, the internal mechanisms won't collapse
# the guide legends. Therefore, we remove the guide legends from
# `geom_tile`.
guides(fill = "none") +
hmanno("t", size = 0.5) +
ggalign() +
geom_bar(aes(fill = value), data = function(x) {
subset(x, !is.na(value))
}) +
hmanno("r", size = 0.5) +
ggalign() +
geom_bar(aes(fill = value), orientation = "y", data = function(x) {
subset(x, !is.na(value))
}) &
scale_fill_brewer(palette = "Dark2", na.translate = FALSE)
maftools
对象可直接输入。
laml.maf <- system.file("extdata", "tcga_laml.maf.gz", package = "maftools")
laml.clin <- system.file("extdata", "tcga_laml_annot.tsv", package = "maftools")
laml <- maftools::read.maf(maf = laml.maf, clinicalData = laml.clin)
ggoncoplot(laml, n_top = 20L, collapse_vars = TRUE) +
# 去掉x轴 labels
scale_x_discrete(breaks = NULL) +
hmanno("r", size = unit(1, "cm")) +
ggalign(
data = function(x) {
# by default, `fortify_heatmap` will attach the gene summary
# into the `gene_anno` attribute
data <- ggalign_attr(x, "gene_anno")
cols <- setdiff(
names(data),
c(
"Tumor_Sample_Barcode", "Hugo_Symbol", "total",
"MutatedSamples", "AlteredSamples"
)
)
ans <- as.matrix(data[, ..cols])
rownames(ans) <- data$Hugo_Symbol
ans
}
) +
geom_bar(aes(x = value, .row_names, fill = .column_names),
stat = "identity"
) +
guides(fill = "none") +
hmanno("t", size = unit(1, "cm")) +
ggalign(
data = function(x) {
# by default, `fortify_heatmap` will attach the sample summary
# into the `sample_anno` attribute
data <- ggalign_attr(x, "sample_anno")
cols <- setdiff(names(data), c("Tumor_Sample_Barcode", "total"))
ans <- as.matrix(data[, ..cols])
rownames(ans) <- data$Tumor_Sample_Barcode
ans
}
) +
geom_bar(aes(y = value, fill = .column_names),
stat = "identity"
) +
guides(fill = "none") &
scale_fill_brewer(palette = "Set3", na.translate = FALSE)
r-universe: https://yunuuuu.r-universe.dev/ggalign
[2]GitHub: https://github.com/Yunuuuu/ggalign
当然了,肿瘤外显子可以做的分析点和可视化非常多,让我们期待一下这个ggplot2热图扩展包(ggalign)的后续更新 :