How to modify labels of complexheatmap
0
0
Entering edit mode
9 months ago
luffy ▴ 110

Hello all,

I have plotted an oncoprint following this link but I am facing trouble in arranging the labels and modifying annotations, here is the code I have used.

Input:

         Sample1      Sample2      Sample3         Sample4        Sample5
Gene1 ""         "Nonsense" ""            ""           "Nonsense" "Nonsense"
Gene2 ""         ""         ""            ""           ""         ""        
Gene3 ""         ""         "Splice_site" ""           ""         ""

code:

## input

mat = read.table('input_oncoprint.txt', header = TRUE, sep = "\t")
mat[is.na(mat)] <- ''
rownames(mat) <- mat[,1]
mat <- mat[,-1]
mat <- mat[, -ncol(mat)]
mat <- t(as.matrix(mat))

col <- c("Missense" = "#f5f251", "Frameshift" = "#a051f5", "Splice_site" = "#5d79f5", "Nonsense" = "#f55dc5", "CNV" = "#f5835d", "Y" = "#78e2fa", "N" = "#78fad3")

alter_fun <- list(
  background = function(x,y,w,h){
    grid::grid.rect(x,y,w - grid::unit(0.5,"mm"), h - grid::unit(0.5,"mm"),gp=grid::gpar(fill = "#CCCCCC",col=NA))
  },
  Missense = function(x,y,w,h){
    grid::grid.rect(x,y,w - grid::unit(0.5,"mm"),h - grid::unit(0.5, "mm"),gp=grid::gpar(fill=col["Missense"],col=NA))
  },
  Nonsense = function(x,y,w,h){
    grid::grid.rect(x,y,w - grid::unit(0.5,"mm"),h - grid::unit(0.5,"mm"),gp = grid::gpar(fill=col["Nonsense"],col=NA))
  },
  CNV = function(x,y,w,h){
    grid::grid.rect(x,y,w - grid::unit(0.5,"mm"),h - grid::unit(0.5,"mm"),gp = grid::gpar(fill=col["CNV"],col=NA))
  },
  Frameshift = function(x,y,w,h){
    grid::grid.rect(x,y,w - grid::unit(0.5,"mm"),h - grid::unit(0.5,"mm"),gp = grid::gpar(fill=col["Frameshift"],col=NA))
  },
  Splice_site = function(x,y,w,h){
grid::grid.rect(x,y,w - grid::unit(0.5,"mm"),h*0.33, gp = grid::gpar(fill=col["Splice_site"],col = NA))
  },
)

column_title <- "Types of Varaints"
heatmap_legend_param <- list(title = "Variant types", at = c("Missense","Frameshift","Splice_site", "Nonsense", "CNV"), labels = c("Missense","Frameshift","Splice_site", "Nonsense", "CNV"))

ha = HeatmapAnnotation(age = anno_points(yearstobirth, ylim = c(0, max(yearstobirth, na.rm = TRUE)), axis = TRUE),annotation_height = unit(c(15), "mm"))

png("plot_onco_fh_consang.png", units="in", width=7, height=7, res=300)
oncoPrint(mat,alter_fun = alter_fun, col = col, column_order = sample_order, column_title = column_title, heatmap_legend_param = heatmap_legend_param, top_annotation = HeatmapAnnotation(Fam_His = fh, his_cons = cansang, col = list(Fam_His = c("Y" = "#f50c7c", "N" = "#fab1d5"), his_cons = c("Y" = "#02c1d6", "N" = "#9ff3fc")), gp = gpar(col = "#9e9d9d")), bottom_annotation = ha)
dev.off()

Output enter image description here

My questions are

  1. How do put the labels one below the other and reduce the size of it so that the plot area would be wide?
  2. How to I reduce the scale of x axis of the bottom annotation plot?
  3. How to change the font of the lables top and bottom annotation?

Thank you for your time
Any help would be much appreciated

R gene oncoprint complexheatmap • 1.4k views
ADD COMMENT
1
Entering edit mode

To change size, fontface etc, you need to supply associated gp parameters. For bottom annotation label font size, for example, use ha = HeatmapAnnotation(age = anno_points(yearstobirth, ylim = c(0, max(yearstobirth, na.rm = TRUE)), axis = TRUE), annotation_name_gp = gpar(size = 2). Change the number until you like the size.

ADD REPLY
0
Entering edit mode

@Ram, Thank you for your response,

  1. Is it possible to print the title of the legend (Family History) and only in short in the top annotation (FH) as full label is overlappingthe bar plot on the right

  2. The code you have shared, i can adjust the plot area in the bottom annotation but how do i scale the Y axis, i can not remove the outliers, is it possible to scale it like 0, 25, 50, 75, 100, 150

Thank you

ADD REPLY
0
Entering edit mode
  1. Yes - explore heatmap legend options. jokergoo has made almost every part of ComplexHeatmap customizable, it just takes some trial and error to get to where you need.
  2. I don't know as I have not used oncoPrint plots using ComplexHeatmap but it might be possible - the outcome may not be what you expect though, since all your data seems to lie at <=12%.
ADD REPLY

Login before adding your answer.

Traffic: 2443 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6