Reputation: 11
using the "oncoPrint" function in "ComplexHeatmap" package I wish to rotate the column names (shown in green in attached image) from being vertical, to being horizontal as this will be easier to read.
I've tried lots of gpar options without success: las, rot, crt, srt
example: column_names_gp = gpar(las=1)
example: ht_global_opt(heatmap_column_names_gp=gpar(las=0))
This must be possible... but how?
Here's my amateurish code followed by some data (the gene names have been changed to protect the innocent).
library(ComplexHeatmap)
Filepath_details<-file.choose()
mat = read.table(Filepath_details, header = TRUE,stringsAsFactors=FALSE, sep = ",")
mat[is.na(mat)] = ""
rownames(mat) = mat[, 1] #define row names as the sample ID.
mat = mat[, -1] #column 1 is now superfluous so delete it.
mat= mat[, -ncol(mat)] #making sure that he whole table id selected.
mat = t(as.matrix(mat))#turning the data into a matrix.
mat[1:3, 1:3] #this just gives a visual check of data processing 3x3 only
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)) }, "nonsense" = function(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","nonsense" = "red", "missense" = "blue")
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
some fictional data to be saved as a text file: ,TOM,DICK,HARRY,FRED,BILL,TOD,ERNIE,ANDY,SIMON,JED,WESS,GARY,PHILL,BURT,JOHN,WALT,DOUG,STAN,HUGH,CLIFF,NATH,EARL,GREG,ED,HENRY,WILL,PAUL,JACK,MICK 2,,,,,,,,,,,,,,,,,missense,,,,,,,,,,,,
5,,,silent,,,,,,,,,,missense,,,,,,silent-missense,,missense,,missense,,,,,,
6,,,,,,,,,,,,,,,,,,,,,,,,,silent,,,,
11,,,,,,,,silent,,,,,,,,,,,,,,,,,,,,,
12,,,,,,,,,,,,,,,,missense,,,,,,,,,,,,missense,
14,,,,,,,,,,,,,,,,,,,,,,,,,,,,missense,
15,,,,,,,,,,,,silent,,missense,,,,,,,,,,,,,,,
17,,,,,,,,silent,,,,silent,,,,,,,,,,,,,,,,missense,
18,,,,,missense,,,,,,,,,,,,missense,,,,,missense,,,,,,,
19,,,,,,,,,,,,,,,,,missense,,,,,,,,,,,,
20,,,silent,,,,,,,,,,,,,,,,,,,,,,,,,missense,
23,,,,,,,,,,,,,,missense,,,,,,,,,,,,,,nonsense,
27,,,,,,,,,,,,,,,,,missense,,,,,,,,,,,,
28,,,missense,,,,,,,silent,,,,,,,,,,,,,,,,,,missense,
29,,missense,,,,,,,missense,,,,,,,,,,,,,,,,,,,,
30,,,,,,missense,,,,,,,,,,,,,,,,,,,,,,,
31,,,,,,,,,,,missense,,,,,,missense,,,,,,,,,,,missense,
39,,,,,,,,,,,,,,,,,,missense,,,,,,,,,,,
42,,,,,,,,,,,,silent,,,,,missense,missense,,,,,,,silent,,,,
43,,,,,,,,,,silent,,,,,,,,,,,,,,,,,,missense,silent
45,,,,silent,,,,,,,,,,,,,,,,,,,,,,,,missense,
46,missense,,,,,,,,,,,,,,,,,,,,,silent-missense,,,,,,missense,
47,,,,,,,,,,missense,,,,,,,,,,,nonsense,,,,,,,,
50,,,,,,,,,,,,,,,,,missense,,,,,,,nonsense,,,,,
51,,,,,,,,,,,,,,,,,,,,missense,,,,,,,,,
52,,,,,,,,,,,,,silent,,missense,,,,silent,,,,,missense,missense,missense,silent,,
60,,,,,,,missense,,,,,,,,,,,,,,,,,,,,,,
63,,,,,,,,,,,,,,,,,,,,,,,,,,,,nonsense,
64,,,,,,,,,,,,,,,,,,,,missense,,,,,,,,missense,
65,,,,,,,,,,,,,,,,,missense,,,,,,,,,,,,
66,,,,,,,,,,,,,silent,,,,,,,,,,,,,,,,
I really hope somebody can help me here... I've not been so stumped with R before.
with thanks...
Andrew
Upvotes: 1
Views: 5227
Reputation: 420
Just a quick update for folks landing on this page: it looks like the package now supports doing this more easily, in other words, without oncoPrint and when specifying the heatmap. Example:
Heatmap(mat, name = "mat", column_names_rot = 45)
Further documentation is here: https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html?q=column_names_rot#dimension-names
Upvotes: 3
Reputation: 1321
I don't think setting the column names horizontal will be easy to read...
However, if you want to this, you can first suppress the column names and add a column annotation which are column names at the bottom of the oncoprint.
First define a column annotation which contain column names, also we calculate the height of the column names:
ha = HeatmapAnnotation(cn = anno_text(colnames(mat), just = "top", offset = unit(1, "npc"))
ha_height = max_text_height(colnames(mat))
Next suppress column names and add the column annotation to the bottom of the heatmap.
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)
Upvotes: 2