is it possible to mark significance levels using heatmap?
    24 ビュー (過去 30 日間)
  
       古いコメントを表示
    
採用された回答
  Drew
    
 2024 年 10 月 30 日
        Text cannot be a child of HeatmapChart, so as an alternative, could use imagesc.
If this answer helps you, please remember to accept the answer.
% Example data matrix and p-value matrix
dataMatrix = rand(10); % Replace with your data matrix
pValueMatrix = rand(10); % Replace with your p-value matrix
% Threshold for p-values
pValueThreshold = 0.1;
% Create a figure and axes
figure;
imagesc(dataMatrix); % Use imagesc to display the data matrix as a heatmap
colormap(sky);
colorbar;
% Get the size of the data matrix
[numRows, numCols] = size(dataMatrix);
% Loop through each element in the matrix
for row = 1:numRows
    for col = 1:numCols
        % Display the data value
        dataValueStr = num2str(dataMatrix(row, col), '%.2f');
        text(col, row, dataValueStr, 'HorizontalAlignment', 'center', ...
            'VerticalAlignment', 'bottom', 'Color', 'black', 'FontSize', 10);
        % Check if the p-value is below the threshold
        if pValueMatrix(row, col) < pValueThreshold
            % Overlay a symbol or p-value text on the heatmap
            % Use '*' for symbol or num2str(pValueMatrix(row, col)) for text
            pValueStr = '*'; % Change to num2str(pValueMatrix(row, col)) to show p-value
            text(col, row, pValueStr, 'HorizontalAlignment', 'center', ...
                'VerticalAlignment', 'top', 'Color', 'red', 'FontSize', 12);
        end
    end
end
% Set axis labels and title
xlabel('Columns');
ylabel('Rows');
title('Heatmap with Data Values and Significant P-values');
% Adjust the axis to display correctly
set(gca, 'XTick', 1:numCols, 'YTick', 1:numRows);
axis equal tight;
その他の回答 (1 件)
  Voss
      
      
 2024 年 10 月 30 日
        As far as I know, there is no built-in option to conditionally alter the heatmap data labels, but what you can do is create a heatmap with no data labels and create an additional invisible axes on top containing text objects that you can manipulate at will.
Example:
data = 100*rand(5)
p = 0.5*rand(5)
h = heatmap(data,'CellLabelColor','none');
str = compose('%0.4g\np=%0.2g',data(:),p(:));
idx = p(:) < 0.05;
str(idx) = strcat(str(idx),'*');
ax = axes( ...
    'Visible','off', ...
    'Units',h.Units, ...
    'Position',h.Position, ...
    'YDir','reverse');
[x,y] = meshgrid(categorical(h.XData),categorical(h.YData));
text(ax,x(:),y(:),str,'HorizontalAlignment','center')
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Data Distribution Plots についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




