【R】 heatmap.2()参数

gplots (version 3.1.1)

heatmap.2: Enhanced Heat Map

This heatmap provides a number of extensions to the standard R heatmap function.

heatmap.2 (x,
           # dendrogram control
           Rowv = TRUE,
           Colv=if(symm)"Rowv" else TRUE,
           distfun = dist,
           hclustfun = hclust,
           dendrogram = c("both","row","column","none"),
           reorderfun = function(d, w) reorder(d, w),
           symm = FALSE,

           # data scaling
           scale = c("none","row", "column"),
           na.rm=TRUE,

           # image plot
           revC = identical(Colv, "Rowv"),
           add.expr,

           # mapping data to colors
           breaks,
           symbreaks=any(x < 0, na.rm=TRUE) || scale!="none",

           # colors
           col="heat.colors",

           # block sepration
           colsep,
           rowsep,
           sepcolor="white",
           sepwidth=c(0.05,0.05),

           # cell labeling
           cellnote,
           notecex=1.0,
           notecol="cyan",
           na.color=par("bg"),

           # level trace
           trace=c("column","row","both","none"),
           tracecol="cyan",
           hline=median(breaks),
           vline=median(breaks),
           linecol=tracecol,

           # Row/Column Labeling
           margins = c(5, 5),
           ColSideColors,
           RowSideColors,
           cexRow = 0.2 + 1/log10(nr),
           cexCol = 0.2 + 1/log10(nc),
           labRow = NULL,
           labCol = NULL,
           srtRow = NULL,
           srtCol = NULL,
           adjRow = c(0,NA),
           adjCol = c(NA,0),
           offsetRow = 0.5,
           offsetCol = 0.5,
           colRow = NULL,
           colCol = NULL,

           # color key + density info
           key = TRUE,
           keysize = 1.5,
           density.info=c("histogram","density","none"),
           denscol=tracecol,
           symkey = any(x < 0, na.rm=TRUE) || symbreaks,
           densadj = 0.25,
           key.title = NULL,
           key.xlab = NULL,
           key.ylab = NULL,
           key.xtickfun = NULL,
           key.ytickfun = NULL,
           key.par=list(),

           # plot labels
           main = NULL,
           xlab = NULL,
           ylab = NULL,

           # plot layout
           lmat = NULL,
           lhei = NULL,
           lwid = NULL,

           # extras
           extrafun=NULL,
           ...
           )

Arguments

  1. x 矩阵数据

    library(gplots)
    mat <- matrix(data = c(0.1, 0.3, 0.4, 0.6,
                           0.2, 0.5, 0.7, 0.8,
                           0.9, 0.15, 0.25, 0.35,
                           0.4, 0.55, 0.65, 0.75), ncol = 4, nrow = 4)
    
    heatmap.2(mat)
    

    heatmap1

  2. Rowv默认为TRUE,即画出行树状图,且如果是整数向量,则根据向量的顺序计算并重新排序。若为FALSE,则不给出树状图且不重新排序。

  3. ColvRowv相同,若输入为方阵,还可以设置Colv = Rowv表明相同设置

    heatmap.2(mat, Rowv = F, Colv = F)
    

    heatmap2

  4. distfunc用于计算行和列之间的距离(相异性)的函数,默认dist

  5. hclustfunRowvColv不是树状图时,用于计算层次聚类的函数,默认为 hclust

  6. dendrogram绘制树状图,参数可以是none,both,column,row,当与RowvColv参数冲突时,以RowvColv为准

  7. reorderfun

  8. symm对称,只有当x为方阵时才有可能设置为TRUE

  9. scale

  10. na.rm

  11. revC

  12. add.expr

  13. breaks设置key的范围

    heatmap.2(mat, Rowv = F, Colv = F,
              breaks = seq(0,1,0.04))
    

    heatmap3

  14. symbreaks

  15. col热图颜色设置

    coul <- colorRampPalette(brewer.pal(8, "PiYG"))(25)
    coul2 <- colorRampPalette(brewer.pal(9, "Purples"))(25)
    heatmap.2(mat, Rowv = F, Colv = F,
              breaks = seq(0,1,0.04),
              col=coul)
    heatmap.2(mat, Rowv = F, Colv = F,
              breaks = seq(0,1,0.04),
              col=coul2)
    

    在这里插入图片描述
    在这里插入图片描述

  16. colsep, rowsep, sepco

  17. sepwidth

  18. cellnote 块里加上数字

  19. notecex note的大小

  20. notecol note的颜色

    heatmap.2(mat, Rowv = F, Colv = F,
              breaks = seq(0,1,0.04),
              col=coul2,
              cellnote = mat,
              notecol = "black",
              notecex = 2)
    

    在这里插入图片描述

  21. na.color NA值的颜色

  22. trace

  23. tracecol

  24. hline, vline, linecol

  25. margins

  26. ColSideColors 长度为 ncol (x) 的字符向量,其中包含可用于标注 x 的列的水平边条的颜色名称。

  27. RowSideColorsColSideColors

    heatmap.2(mat, Rowv = F, Colv = F,
              breaks = seq(0,1,0.04),
              col=coul2,
              cellnote = mat,
              notecol = "black",
              notecex = 2,
              RowSideColors = c("red","blue","red","blue"),
              ColSideColors = c("red","blue","red","blue")
    )
    

    在这里插入图片描述

  28. cexRow, cexCol

    heatmap.2(mat, Rowv = F, Colv = F,
              breaks = seq(0,1,0.04),
              col=coul2,
              cellnote = mat,
              notecol = "black",
              notecex = 2,
              cexRow = 4,cexCol = 4
    )
    

    在这里插入图片描述

  29. labRow, labCol重新设置坐标轴名称

    heatmap.2(mat, Rowv = F, Colv = F,
              breaks = seq(0,1,0.04),
              col=coul2,
              cellnote = mat,
              notecol = "black",
              notecex = 2,
              cexRow = 2,cexCol = 2,
              labRow = c("A","B","C","D"), labCol = c("E","F","G","H")
    )
    

    在这里插入图片描述

  30. srtRow, srtCol 行列坐标旋转角度

    heatmap.2(mat, Rowv = F, Colv = F,
              breaks = seq(0,1,0.04),
              col=coul2,
              cellnote = mat,
              notecol = "black",
              notecex = 2,
              cexRow = 2,cexCol = 2,
              labRow = c("A","B","C","D"), labCol = c("E","F","G","H"),
              srtCol = 0 
    )
    

    在这里插入图片描述

  31. adjRow, adjCol

  32. offsetRow, offsetCol 调整坐标轴标签上下位置

  33. colRow, colCol

    heatmap.2(mat, Rowv = F, Colv = F,
              breaks = seq(0,1,0.04),
              col=coul2,
              cellnote = mat,
              notecol = "black",
              notecex = 2,
              cexRow = 2,cexCol = 2,
              labRow = c("A","B","C","D"), labCol = c("E","F","G","H"),
              srtCol = 0,
              colRow = "red", colCol = c("red","blue","green","pink")
    )
    

    在这里插入图片描述

  34. key logical indicating whether a color-key should be shown.

  35. keysize key大小

  36. key.title

  37. key.xlab

  38. key.ylab

    heatmap.2(mat, Rowv = F, Colv = F,
              breaks = seq(0,1,0.04),
              col=coul2,
              cellnote = mat,
              notecol = "black",
              notecex = 2,
              cexRow = 2,cexCol = 2,
              labRow = c("A","B","C","D"), labCol = c("E","F","G","H"),
              srtCol = 0,
              colRow = "red", colCol = c("red","blue","green","pink"),
              keysize = 1, key.title = "title", key.xlab = "xlab", key.ylab = "ylab"
    )
    

    在这里插入图片描述

  39. key.xtickfun

  40. key.ytickfun

  41. key.par

  42. density.info

  43. denscol

  44. symkey

  45. densadj

  46. main, xlab, ylab

  47. lmat, lhei, lwid 控制plot位置

  48. extrafun

R文档
暂时只用到了这些,其余的以后用到补充

在R中使用heatmap.2画热图时,可以通过以下方式进行美化: 1. 修改颜色方案:可以使用colorRampPalette函数生成自定义的颜色方案,然后通过col参数进行设置。也可以使用预定义的颜色方案,例如rainbow、heat.colors等。 2. 调整标签字体大小和角度:可以使用cexRow和cexCol参数来调整行和列标签的字体大小,使用lhei和lwid参数来调整标签的高度和宽度,使用lmat参数来调整标签的位置。可以使用las参数来调整标签的角度。 3. 去除边框和网格线:可以使用border和trace参数将边框和网格线设置为透明。 4. 调整图像大小和比例:可以使用width和height参数来调整图像的大小,使用symm参数来控制是否对称显示。 5. 添加图例:可以使用key参数添加图例,通过key.title参数设置图例的标题,通过key.xlab和key.ylab参数设置图例的横轴和纵轴标签。 下面是一个示例代码: ```R library(gplots) # 生成数据 data(mtcars) mtcars_matrix <- as.matrix(mtcars) # 绘制热图 heatmap.2(mtcars_matrix, scale = "column", col = colorRampPalette(c("blue", "white", "red"))(100), trace = "none", dendrogram = "column", margins = c(10, 10), cexRow = 0.5, cexCol = 0.5, lhei = c(0.5, 4), lwid = c(0.5, 4), las = 2, key = TRUE, key.title = "Legend", key.xlab = "X Axis", key.ylab = "Y Axis", symm = TRUE, density.info = "none", main = "Heatmap of mtcars", xlab = "Cars", ylab = "Features") ``` 运行以上代码,你可以得到一个美化过的热图。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值