oisyutat
oisyutat

Reputation: 197

How to reduce the height of the heatmap itself while increasing the height of the horizontal side bar?

In the heatmap.2 function in the gplots package, how can I reduce the height of the rows in the heatmap itself while increasing the height of the horizontal side bar (denoted by ColSideColors argument)?

library('gplots')
prob_matrix=replicate(100, rnorm(20)) 
ids=paste("patient",c(1:100),sep="_")
type_colors=sample(c("red","blue","cyan","pink","yellow","green"), length(ids), replace = TRUE, prob = NULL)
heatmap.2(prob_matrix, ColSideColors=type_colors,RowV=NULL,trace="none")

I would like the horizontal side bar generated by ColSideColors=subtype_colors to be increased in height, and the rows of the heatmap reduced in height.

For extension, how can I also edit the width of each column independent of the size of the width of the pdf or graphics device to which I output the plot? So, in the above, I would want to make the width of the columns of the prob_matrix heatmap greater.

Upvotes: 1

Views: 1089

Answers (1)

Spacedman
Spacedman

Reputation: 94182

I think its hard coded into the function. Roundabout line 196 of the heatmap.2 function there is:

if (!missing(ColSideColors)) {
            if (!is.character(ColSideColors) || length(ColSideColors) != 
                nc) 
                stop("'ColSideColors' must be a character vector of length ncol(x)")
            lmat <- rbind(lmat[1, ] + 1, c(NA, 1), lmat[2, ] + 
                1)
            lhei <- c(lhei[1], 0.2, lhei[2])
        }

And that 0.2 is the height assigned to the colour bars. If you make a copy of heatmap.2 and edit it you can set that to something else. Create a new argument, ColSideHeight maybe, with default 0.2, and change that 0.2 to ColSideHeight.

Upvotes: 1

Related Questions