I am using the consensusPlot.m function from Lucas G. S. Jeub's HierarchicalConsensus MATLAB package to create a heatmap with dendrogram on the right. I input a square matrix C and want the heatmap to be square. However, consensusPlot.m function by default returns a rectangular heatmap.
Here is the sample data and modified consensusPlot.m together with dependend functions. Below is the code:
% Load data
ScTree = load('ScTree.mat');
Sc = ScTree.Sc;
Tree = ScTree.Tree;
C = load('C.mat');
C = C.C;
% Draw heatmap
consensusPlot(C, Sc, Tree);
set(gcf, 'PaperSize', [6 6]);
print(gcf, '-dpdf', 'Fig.pdf');
I looked into consensusPlot.m function and found the following most relevant code snippet for creating heatmap:
parseArgs=inputParser();
addParameter(parseArgs,'GroundTruth',[]);
addParameter(parseArgs,'Labels',{});
addParameter(parseArgs,'LabelFont',6);
addParameter(parseArgs,'ImageRescale',1);
parse(parseArgs,varargin{:});
Sgtruth=parseArgs.Results.GroundTruth;
labels=parseArgs.Results.Labels;
ylabelfont=parseArgs.Results.LabelFont;
imrescale=parseArgs.Results.ImageRescale;
clf()
ax_C_int=axes('position',[0.1,0.1,0.7,0.8]);
ax_H_int=axes('position',[0.8,0.1,0.1,0.8]);
N=length(C);
ylims=[0.5+0.5*1/imrescale,N+0.5-0.5*1/imrescale];
s_int=treeSort(C,Sc,Tree);
imagesc(ax_C_int,ylims,ylims, imresize(C(s_int,s_int),imrescale,'nearest'));
if ~isempty(labels)
set(ax_C_int,'ytick',1:N,'yticklabel',labels(s_int),...
'xtick',1:N,'xticklabel',labels(s_int),'xticklabelrotation',90,...
'ticklabelinterpreter','None','fontsize',ylabelfont)
end
The heatmap is on the left and dendrogram is on the right of the final image. The default width of the heatmap is 0.7 and default height is 0.8. When I set ax_C_int=axes('position',[0.1,0.1,0.7,0.7]);, the heatmap becomes even more enlongated. I am wondering how should I modify the original code to create a square heatmap.
I have two additional requirement:
There should be no space between the heatmap and the dendrogram;
I modified the code to add color bar below the heatmap, which is of equal width to the heatmap. I want to ensure that when the heatmap becomes square, the color bar remains of equal width to the heatmap.