R:包“ComplexHeatmap”:oncoPrint:如何旋转列名。它们默认为垂直,我想要水平

时间:2016-04-12 11:01:14

标签: r heatmap columnname

使用“ComplexHeatmap”包中的“oncoPrint”功能我希望将列名(在附加图像中以绿色显示)从垂直旋转到水平,因为这样更容易阅读。

我尝试了很多gpar选项而没有成功:las,rot,crt,srt

示例:column_names_gp = gpar(las = 1)

示例:ht_global_opt(heatmap_column_names_gp = gpar(las = 0))

这一定是可能的......但是如何?

这是我的业余代码,后跟一些数据(基因名称已被更改以保护无辜者)。

  

库(ComplexHeatmap)

     

Filepath_details< -file.choose()

     

mat = read.table(Filepath_details,header = TRUE,stringsAsFactors = FALSE,sep =“,”)

     

mat [is.na(mat)] =“”

     

rownames(mat)= mat [,1] #define行名称作为样本ID。

     

mat = mat [,-1] #column 1现在是多余的,所以删除它。

     

mat = mat [,-ncol(mat)] #making确保他选择了整个表格。

     

mat = t(as.matrix(mat))#将数据转换为矩阵。

     

mat [1:3,1:3]#这只是对3x3数据处理进行目测检查

     

alter_fun_list = list(        background = function(x,y,w,h){            grid.rect(x,y,w-unit(0.5,“mm”),h-unit(0.5,“mm”),gp = gpar(fill =“#CCCCCC”,col = NA))        },        “废话”=函数(x,y,w,h){            grid.rect(x-0.008,y,w * 0.45,h-unit(0.5,“mm”),gp = gpar(fill =“red”,col = NA))        },        “missense”= function(x,y,w,h){            grid.rect(x-0.008,y,w * 0.45,h-unit(0.5,“mm”),gp = gpar(fill =“blue”,col = NA))        },        “silent”= function(x,y,w,h){            grid.rect(x + 0.008,y,w * 0.45,h-unit(0.5,“mm”),gp = gpar(fill =“forestgreen”,col = NA))        }    )

     

col = c(“silent”=“forestgreen”,“废话”=“红色”,“missense”=“蓝色”)

     

oncoPrint(mat,get_type = function(x)strsplit(x,“ - ”)[1],        alter_fun_list = alter_fun_list,col = col,show_column_names = TRUE,column_names_gp = gpar(cex = 0.5,font = 1,col =“green”),heatmap_legend_param = list(title =“Mutations”))

A tiff image of some fictional gene mutation data

将一些虚构数据保存为文本文件: ,汤姆,迪克,哈利,FRED,BILL,TOD,摇奖,ANDY,SIMON,JED,WESS,GARY,菲尔,伯特,JOHN,WALT,DOUG,STAN,休,悬崖,纳特EARL,GREG,ED,HENRY将,保罗,杰克,MICK 2 ,,,,,,,,,,,,,,,,,错义,,,,,,,,,,,,

5 ,,,无声,,,,,,,,,,错义,,,,,,无声错义,,错义,,错义,,,,,,

6 ,,,,,,,,,,,,,,,,,,,,,,,,,无声,,,,

11 ,,,,,,,,无声,,,,,,,,,,,,,,,,,,,,,

12 ,,,,,,,,,,,,,,,,错义,,,,,,,,,,,,错义,

14 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,错义,

15 ,,,,,,,,,,,,无声,,错义,,,,,,,,,,,,,,,

17 ,,,,,,,,无声,,,,无声,,,,,,,,,,,,,,,,错义,

18 ,,,,,错义,,,,,,,,,,,,错义,,,,,错义,,,,,,,

19 ,,,,,,,,,,,,,,,,,错义,,,,,,,,,,,,

20 ,,,无声,,,,,,,,,,,,,,,,,,,,,,,,,错义,

23 ,,,,,,,,,,,,,,错义,,,,,,,,,,,,,,无义,

27 ,,,,,,,,,,,,,,,,,错义,,,,,,,,,,,,

28 ,,,错义,,,,,,,无声,,,,,,,,,,,,,,,,,,错义,

29,错义,,,,,,,错义,,,,,,,,,,,,,,,,,,,,

30 ,,,,,,错义,,,,,,,,,,,,,,,,,,,,,,,

31 ,,,,,,,,,,,错义,,,,,,错义,,,,,,,,,,,错义,

39 ,,,,,,,,,,,,,,,,,,错义,,,,,,,,,,,

42 ,,,,,,,,,,,,无声,,,,,错义,错义,,,,,,,无声,,,,

43 ,,,,,,,,,,无声,,,,,,,,,,,,,,,,,,错义,沉默

45 ,,,,无声,,,,,,,,,,,,,,,,,,,,,,,,错义,

46,错义,,,,,,,,,,,,,,,,,,,,,无声错义,,,,,,错义,

47 ,,,,,,,,,,错义,,,,,,,,,,,无义,,,,,,,,

50 ,,,,,,,,,,,,,,,,,错义,,,,,,,无义,,,,,

51 ,,,,,,,,,,,,,,,,,,,,错义,,,,,,,,,

52 ,,,,,,,,,,,,,无声,,错义,,,,无声,,,,,错义,错义,错义,无声,,

60 ,,,,,,,错义,,,,,,,,,,,,,,,,,,,,,,

63 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,无义,

64 ,,,,,,,,,,,,,,,,,,,,错义,,,,,,,,错义,

65 ,,,,,,,,,,,,,,,,,错义,,,,,,,,,,,,

66 ,,,,,,,,,,,,,无声,,,,,,,,,,,,,,,,

我真的希望有人能在这里帮助我...我以前没有被R这么难过。

谢谢......

安德鲁

1 个答案:

答案 0 :(得分:1)

我不认为将列名设置为水平将很容易阅读...

但是,如果要这样做,可以先取消列名称,然后添加列注释,这些列注释是oncoprint底部的列名。

首先定义一个包含列名的列注释,同时我们计算列名的高度:

ha = HeatmapAnnotation(cn = anno_text(colnames(mat), just = "top", offset = unit(1, "npc"))
ha_height = max_text_height(colnames(mat))

接下来禁止列名称并将列注释添加到热图的底部。

oncoPrint(mat, get_type = function(x) strsplit(x, "-")[1], 
    alter_fun_list = alter_fun_list, col = col, 
    show_column_names = FALSE, 
    column_names_gp = gpar(cex=0.5, font=1, col= "green"), 
    heatmap_legend_param = list(title = "Mutations"),
    bottom_annotation = ha, bottom_annotation_height = ha_height)