How to remove the gene label in heatmap RNA-seq
2
1
Entering edit mode
5 months ago
Chris ▴ 260

Hi all,

I have difficulty to remove the gene label (black column on the right) after trying all the papameters. Would you please have a suggestion? Also I don't know how to show the sample name (4 samples in this case). I appreciate your help! The code is adapt from this post: Issues marking genes in ComplexHeatmap

  genes_to_show <- c("CCN1")
    mark_at = which(rownames(sigs.df) %in% genes_to_show)
    ha = rowAnnotation(foo = anno_mark(at = which(rownames(sigs.df) %in% genes_to_show),
                                       labels = rownames(sigs.df)[rownames(sigs.df)%in%genes_to_show]))
    Heatmap(mat.z, 
            name = "Z-score - log2CPM", 
            col = circlize::colorRamp2(c(-2, 0, 2), c("blue", "black", "red")),
            na_col = "grey",
            cluster_rows = T,
            cluster_columns = T,
            right_annotation = ha,
            row_names_max_width = unit(10,"in"),
            row_title_gp = gpar(fontsize = 15),
            column_title_gp = gpar(fontsize = 20),
            column_names_gp = gpar(fontsize =10),
            row_names_gp = gpar(fontsize =3),
            show_column_names = T)

enter code here

complexheatmap • 894 views
ADD COMMENT
3
Entering edit mode
5 months ago
Heatmap(mat.z, 
            name = "Z-score - log2CPM", 
            col = circlize::colorRamp2(c(-2, 0, 2), c("blue", "black", "red")),
            na_col = "grey",
            cluster_rows = TRUE,
            cluster_columns = TRUE,
            right_annotation = ha,
            row_names_max_width = unit(10,"in"),
            row_title_gp = gpar(fontsize = 15),
            column_title_gp = gpar(fontsize = 20),
            column_names_gp = gpar(fontsize =10),
            row_names_gp = gpar(fontsize =3),
            show_column_names = TRUE,
            show_row_names = FALSE)

See show_row_names. Also, don't use T and F in place of TRUE and FALSE, as they are interpreted as variables and thus can be overwritten.

ADD COMMENT
0
Entering edit mode

Thanks jared.andrews07! I could remove the row names with show_row_names = FALSE, however, show_column_names = TRUE didn't show the column name. Would you please have a suggestion?

ADD REPLY
1
Entering edit mode

Does your matrix have column names?

ADD REPLY
3
Entering edit mode
5 months ago
Barry Digby ★ 1.3k

To follow up on Jared's suggestions - It should work.

See the minimal examples below and double-check your code against it:

set.seed(123)
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")

genes_to_show <- c("Gene10")
mark_at = which(rownames(test) %in% genes_to_show)
ha = rowAnnotation(foo = anno_mark(at = which(rownames(test) %in% genes_to_show),
                                       labels = rownames(test)[rownames(test)%in%genes_to_show]))

Heatmap(test, name="Zscore", show_column_names = TRUE, column_names_gp = gpar(fontsize =10), right_annotation = ha, show_row_names = FALSE)

enter image description here

You could also do this

set.seed(123)
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")

genes_to_show <- c("Gene10")
mark_at = which(rownames(test) %in% genes_to_show)
ha = rowAnnotation(foo = anno_mark(at = which(rownames(test) %in% genes_to_show),
                                       labels = rownames(test)[rownames(test)%in%genes_to_show]))

# Create our own row dendrogram (ComplexHeatmap orders rows by mean by default)
dend <- reorder(as.dendrogram(hclust(dist(test))), -rowMeans(test), agglo.FUN = mean)

# Find rows in dendrogram
dend_idx <- which(order.dendrogram(dend) %in% which(rownames(test) %in% genes_to_show))

# Find bottom and top of each row on heatmap (x and y axes go from 0 to 1)
btm <- 1 - (dend_idx / nrow(test))
top <- btm + (1/nrow(test))


Heatmap(test, name="Zscore", cluster_rows = dend, show_column_names = TRUE, column_names_gp = gpar(fontsize =10), right_annotation = ha, show_row_names = FALSE, border = T, border_gp = gpar(lwd=2))

box_col <- 'black'
box_width <- 2
decorate_heatmap_body("Zscore", { for (i in 1:length(genes_to_show)) {
  grid.lines(c(0, 1), c(top[i],top[i]), gp = gpar(lty = 1, lwd = box_width, col = box_col))
  grid.lines(c(0, 1), c(btm[i],btm[i]), gp = gpar(lty = 1, lwd = box_width, col = box_col))
}
})

enter image description here

ADD COMMENT

Login before adding your answer.

Traffic: 2911 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