legend with gradient in ComplexHeatmap
2
0
Entering edit mode
AR3513 • 0
@ar3513-11025
Last seen 4.2 years ago

Hello, 

I have noticed that the legend for the colors of the heatmaps it has a fix number of breaks (5). Even if I customize the colors myself to include more breaks using colorRamp2, or if I use a continuous scale,  it stills displays only 5 breaks in the legend. 

Is there anyway to change the number of breaks in the legend?

Thanks very much, 

Andrea

complexheatmap • 2.6k views
ADD COMMENT
1
Entering edit mode
Mike Smith ★ 6.6k
@mike-smith
Last seen 1 hour ago
EMBL Heidelberg

You can do this with the heatmap_legend_param argument.  First we'll create a heatmap with the example from the ComplexHeatmap vignette:

library(ComplexHeatmap)
library(circlize)

set.seed(123)

mat = cbind(rbind(matrix(rnorm(16, -1), 4), matrix(rnorm(32, 1), 8)),
            rbind(matrix(rnorm(24, 1), 4), matrix(rnorm(48, -1), 8)))

# permute the rows and columns
mat = mat[sample(nrow(mat), nrow(mat)), sample(ncol(mat), ncol(mat))]

rownames(mat) = paste0("R", 1:12)
colnames(mat) = paste0("C", 1:10)

If we plot this with the default settings it has 5 color levels in the legend e.g.

Heatmap(mat)

We can increase this like so:

Heatmap(mat, heatmap_legend_param = list(at = -5:5))

 

ADD COMMENT
0
Entering edit mode
AR3513 • 0
@ar3513-11025
Last seen 4.2 years ago

Awesome!! Thanks very much !

 

Andrea

ADD COMMENT

Login before adding your answer.

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