分享

ggheatmap2.0版本

 健明 2021-07-18

前面我们推送了南方医的一个后起之秀的新R包:快来使用ggheatmap强化你的热图吧!已经正式被R语言社区的CRAN接受了,大家可以放心的使用起来!而且作者还给出来了一个实例:ggheatmap复现CNS级美图,更难能可贵的是一直在坚持更新,这不,ggheatmap2.0版本就发布了!

下面是包作者的投稿

CRAN链接:https://cran./web/packages/ggheatmap/index.html

Github链接:https://github.com/XiaoLuo-boy/ggheatmap

ggheatmap1.0潜在问题

问题1:结构相对复杂,不能很灵活地使用ggplot2系列函数

问题2:功能相对较少,有伙伴建议拓展一下相关性热图的绘制

问题3.可视化的功能相较欠缺

ggheatmap2.0版本

说明:

整合各位读者的建议和反馈。这次更新主要在于

  • ggheatmapggplot2theme函数的联动,减少参数。同时可以自由调整图例、字体大小、颜色、字体等样式。删除下列参数

    text_angle_rows
    text_angle_cols 
    text_color_rows 
    text_color_cols
    text_face_rows
    text_face_cols
    text_just_rows
    text_just_cols
    text_show_rows
    text_show_cols
  • 增加热图单元格形状(包括:圆形、方形和三角形)。增加参数(至于相关性热图的绘制,已经有很多优秀的gg系列R包来做,大家可以学习一下)

    shape
  • 增加注释和聚类树的位置调整参数。增加参数

    annotation_position_rows
    annotation_position_cols
    tree_position_rows
    tree_position_cols
  • 添加单元格边界。增加参数

    border

创建数据

devtools::install_github("XiaoLuo-boy/ggheatmap")
library(ggheatmap)
library(tidyr)
set.seed(123)
df <- matrix(runif(225,0,10),ncol = 15)
colnames(df) <- paste("sample",1:15,sep = "")
rownames(df) <- sapply(1:15, function(x)paste(sample(LETTERS,3,replace = F),collapse = ""))
df[1:4,1:4]


row_metaData <- data.frame(exprtype=sample(c("Up","Down"),15,replace = T),
                           genetype=sample(c("Metabolism","Immune","None"),15,replace = T))
rownames(row_metaData) <- rownames(df)
col_metaData <- data.frame(tissue=sample(c("Normal","Tumor"),15,replace = T),
                           risklevel=sample(c("High","Low"),15,replace = T))
rownames(col_metaData) <- colnames(df)
exprcol <- c("#EE0000FF","#008B45FF" )
names(exprcol) <- c("Up","Down")
genecol <- c("#EE7E30","#5D9AD3","#D0DFE6FF")
names(genecol) <- c("Metabolism","Immune","None")
tissuecol <- c("#98D352","#FF7F0E")
names(tissuecol) <- c("Normal","Tumor")
riskcol <- c("#EEA236FF","#46B8DAFF")
names(riskcol) <- c("High","Low")
col <- list(exprtype=exprcol,genetype=genecol,tissue=tissuecol,risklevel=riskcol)
text_rows <- sample(rownames(df),3)

p<- ggheatmap(df,cluster_rows = T,cluster_cols = T,scale = "row",
              text_show_rows = text_rows,
              cluster_num = c(3,3),
              tree_color_rows = c("#008B45FF","#631879FF","#008280FF"),
              tree_color_cols = c("#1F77B4FF","#FF7F0EFF","#2CA02CFF"),
              annotation_rows = row_metaData,
              annotation_cols = col_metaData,
              annotation_color = col
)
p

更新1:theme系统

ggheatmap_plotlist(p)

说明:由于后续使用theme函数,需要填plotlist参数。ggheatmap_plotlist函数可以清晰的知道热图的组图单元。其中可以使用theme函数的组图单元,其上面有”plotlist + 编号“

p%>%
  ggheatmap_theme(1:5,
                  theme =list(
                    theme(axis.text.x = element_text(angle = 90,face = "bold",size = 10),
                          axis.text.y = element_text(colour = "red",face = "bold")),
                    theme(legend.title = element_text(face = "bold")),
                    theme(legend.title = element_text(face = "bold")),
                    theme(legend.title = element_text(face = "bold")),
                    theme(legend.title = element_text(face = "bold"))
                    ))

更新2:设置单元格形状

ggheatmap(df,cluster_rows = T,cluster_cols = T,scale = "row",
          text_show_rows = text_rows,
          border = "grey",
          shape = "circle",
          cluster_num = c(3,3),
          tree_color_rows = c("#008B45FF","#631879FF","#008280FF"),
          tree_color_cols = c("#1F77B4FF","#FF7F0EFF","#2CA02CFF"),
          annotation_rows = row_metaData,
          annotation_cols = col_metaData,
          annotation_color = col
)%>%
  ggheatmap_theme(1,theme =list(theme(axis.text.x = element_text(angle = 90,face = "bold",size = 10),
                                      axis.text.y = element_text(colour = "red",face = "bold"))))

更新3:增加注释和聚类树的位置调整参数

ggheatmap(df,cluster_rows = T,cluster_cols = T,scale = "row",
          text_show_rows = text_rows,
          border = "grey",
          cluster_num = c(3,3),
          tree_color_rows = c("#008B45FF","#631879FF","#008280FF"),
          tree_color_cols = c("#1F77B4FF","#FF7F0EFF","#2CA02CFF"),
          annotation_rows = row_metaData,
          annotation_cols = col_metaData,
          annotation_color = col,
          text_position_rows = "left",
          text_position_cols = "top",
          tree_position_rows = "right",
          tree_position_cols = "bottom",
          annotation_position_rows = "right",
          annotation_position_cols = "bottom"
          
)%>%
  ggheatmap_theme(1,theme =list(theme(axis.text.x = element_text(angle = 90,face = "bold",size = 10),
                                      axis.text.y = element_text(colour = "red",face = "bold"))))

更新4:添加单元格边界

ggheatmap(df,cluster_rows = T,cluster_cols = T,scale = "row",
              text_show_rows = text_rows,
              border = "grey",
              cluster_num = c(3,3),
              tree_color_rows = c("#008B45FF","#631879FF","#008280FF"),
              tree_color_cols = c("#1F77B4FF","#FF7F0EFF","#2CA02CFF"),
              annotation_rows = row_metaData,
              annotation_cols = col_metaData,
              annotation_color = col
)%>%
  ggheatmap_theme(1,theme =list(theme(axis.text.x = element_text(angle = 90,face = "bold",size = 10),
                          axis.text.y = element_text(colour = "red",face = "bold"))))

致谢

衷心感谢南方医科大学余光创老师和“生信技能树”健明老师对我的认可以及对ggheatmap的推送,使ggheatmap能够让更多的同仁知道和了解。感谢各位使用者和读者对ggheatmap的使用反馈和建议,让ggheatmap进一步得到完善和升级。希望在后续的使用过程中,大家也不吝赐教~。作者邮箱为:2734782653@qq.com

文末友情推荐

本科生都如此优秀了,你还在等什么!

如果你对开发自己的R包感兴趣, 不要犹豫了,我们有一个公开课, 进群方式见:Y叔神包clusterProfiler更新到4啦(大家一起来写包吧)

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多