I am producing heatmaps with heatmap.2. I know how to controls many of the parameters but still I have not found a way of making the key of color only wider or putting it as a strip in a side or bottom of the plot.
With keysize it modifies both height and width proportionally.
Also when using ColSideColors I am using legend() to put the color labels, but 'topright' is not at the top-right. I know that this is something about the plot area, margins etc, but I have not found yet a good explanatory text of how heatmap.2 plot is structured and how to positioned things by coordinates and how to deal with oma, mar etc. Depending on the margins, samples, tree depth, etc. the legend could be placed in an open area or overlaps a bit of the heatmap. Any point to good texts for understanding theses issues with R graphics would be truly appreciated.
The coded used is:
df<- data.frame( x1=rnorm(120,mean=rep(1:3,each=4),sd=0.2)
,x2=rnorm(120,mean=rep(1:3,each=4),sd=0.2)
,x3=rnorm(120,mean=rep(1:3,each=4),sd=0.2)
,x4=rnorm(120,mean=rep(1:3,each=4),sd=0.2)
,x5=rnorm(120,mean=rep(1:3,each=4),sd=0.2)
,x6=rnorm(120,mean=rep(1:3,each=4),sd=0.2)
,x7=rnorm(120,mean=rep(1:3,each=4),sd=0.2)
,x8=rnorm(120,mean=rep(1:3,each=4),sd=0.2)
,y1=rnorm(120,mean=rep(c(1,2,1),each=4),sd=0.2)
,y2=rnorm(120,mean=rep(c(1,2,1),each=4),sd=0.2)
,y3=rnorm(120,mean=rep(c(1,2,1),each=4),sd=0.2)
,y4=rnorm(120,mean=rep(c(1,2,1),each=4),sd=0.2)
,y5=rnorm(120,mean=rep(c(1,2,1),each=4),sd=0.2)
,y6=rnorm(120,mean=rep(c(1,2,1),each=4),sd=0.2)
,y7=rnorm(120,mean=rep(c(1,2,1),each=4),sd=0.2)
,y8=rnorm(120,mean=rep(c(1,2,1),each=4),sd=0.2)
)
dataMatrix <- as.matrix(df)[sample(1:120),]
heatmap.2(dataMatrix
, col=rev(brewer.pal(11,"RdBu"))
, density.info="none"
, key=TRUE
, symkey=FALSE
, trace="none"
, cexRow=1
, scale='row'
, margins =c(10,9)
, ColSideColors=c(rep("red", ncol(df)/2), rep("green", ncol(df)/2))
, main="Log2_intensities median centered"
, keysize=0.9)
legend('topright', c("x", "y"),lty=1, col=c("red", "green"), cex=0.8)