heatmap help - how to display grouped data across 3 levels (LO, MED, HI) ?

10 visualizzazioni (ultimi 30 giorni)
How can I show 3 levels in a heatmap (LO MED, HI) and not just two (FALSE, TRUE for example) across n=4 GROUPS for a single outcome variable (continuous variable)? And is it possbile to (also) show % of total for the OUTCOME variable by GROUP? and not just mean or median.
Here is some working code and a dataset, but displays only two levels (LO, HI) for each GROUP:
load CHRX.mat % loads as CH = Chelsea; RX = Roxbury
P = prctile(CH.VLFN, 75);
isVHI = CH.VLFN>=P==1;
VHI = isVHI; % this is the HIGH level
P1 = prctile(CH.VLFN, 25);
isVLO = CH.VLFN<=P1==1;
VLO = isVLO; % thius is the LOW level
isIQR = ~VHI&~VLO==1;
IQR = isIQR; % this is the MEDIUM level
CH1 = addvars(CH, VLO); CH2 = addvars(CH1 ,IQR); CH3 = addvars(CH2, VHI)
CH3 = 40914×26 table
DateTime LAeq VLFN LFN MFN HFN Day Season DayNumber Wkend RushHR Site Temp Hum WD_Deg ImpactWind WS Rain mbBar WS_HI RF UFPConc lnUFP VLO IQR VHI ____________________ _____ ______ ______ ______ ______ _____ ______ _________ _____ ______ _____ ____ _____ ______ __________ ______ ____ ______ _____ _____ _______ ______ _____ _____ _____ 15-Apr-2016 12:34:00 54.15 82.3 68.426 57.616 53.474 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 22575 10.025 false false true 15-Apr-2016 12:36:00 53.25 79.223 66.039 55.502 53.072 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 14450 9.5784 false false true 15-Apr-2016 12:39:00 53.7 77.488 67.369 56.525 53.579 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 12500 9.4335 false false true 15-Apr-2016 12:41:00 54.8 70.488 69.756 56.901 54.207 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 18820 9.8427 false true false 15-Apr-2016 12:43:00 63.55 72.117 70.894 58.103 63.814 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 19750 9.8909 false false true 15-Apr-2016 12:44:00 53.75 73.194 70.446 56.569 52.921 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 22250 10.01 false false true 15-Apr-2016 12:45:00 52.65 65.916 68.539 54.082 52.55 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 27800 10.233 false true false 15-Apr-2016 12:46:00 53.3 71.771 69.697 54.478 52.908 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 20400 9.9233 false false true 15-Apr-2016 12:47:00 54.95 69.95 69.938 56.176 54.107 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 11700 9.3673 false true false 15-Apr-2016 12:49:00 53.9 65.075 69.134 54.696 52.966 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 16700 9.7232 false true false 15-Apr-2016 12:50:00 53.8 72.045 69.219 55.651 53.241 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 13150 9.4842 false false true 15-Apr-2016 12:51:00 59.85 72.058 70.259 59.153 59.137 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 14380 9.5736 false false true 15-Apr-2016 12:52:00 56.3 70.284 70.176 57.921 55.563 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 14100 9.5539 false true false 15-Apr-2016 12:54:00 55.4 65.599 71.151 57.015 54.276 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 17300 9.7585 false true false 15-Apr-2016 12:55:00 54.7 63.082 68.384 55.673 54.231 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 21600 9.9804 false true false 15-Apr-2016 12:57:00 53.25 74.909 68.499 54.707 53.208 true false 6 false false false 8.9 34.06 80 railway 16.668 0 1031.3 false false 12350 9.4214 false false true
%% HEATMAPS
% note: ImpactWind is the GROUP categorical variable (n=4)
% note: UFPConc is the OUTCOME, continuous variable or ColorVariable
format shortG
data = CH3; % Chelsea
figure()
h = heatmap(data,'ImpactWind','VHI','ColorVariable','UFPConc')
h =
HeatmapChart (Mean of UFPConc) with properties: SourceTable: [40914×26 table] XVariable: 'ImpactWind' YVariable: 'VHI' ColorVariable: 'UFPConc' ColorMethod: 'mean' Use GET to show all properties
h.YDisplayLabels = {'LO','HI'}
h =
HeatmapChart (Mean of UFPConc) with properties: SourceTable: [40914×26 table] XVariable: 'ImpactWind' YVariable: 'VHI' ColorVariable: 'UFPConc' ColorMethod: 'mean' Use GET to show all properties

Risposta accettata

Voss
Voss il 10 Gen 2024
You can make a variable that has three distinct values, say 0 for LO, 1 for MEDIUM, and 2 for HI, which can be constructed as follows:
level = 2*VHI + IQR;
and then add that variable to your table and create the heatmap based on that.
load CHRX.mat % loads as CH = Chelsea; RX = Roxbury
VHI = CH.VLFN >= prctile(CH.VLFN, 75); % this is the HIGH level
VLO = CH.VLFN <= prctile(CH.VLFN, 25); % this is the LOW level
IQR = ~VHI & ~VLO; % this is the MEDIUM level
level = VHI*2+IQR;
CH = addvars(CH,level);
%% HEATMAPS
% note: ImpactWind is the GROUP categorical variable (n=4)
% note: UFPConc is the OUTCOME, continuous variable or ColorVariable
format shortG
data = CH; % Chelsea
figure()
h = heatmap(data,'ImpactWind','level','ColorVariable','UFPConc');
h.YDisplayLabels = {'LO','MED','HI'};

Più risposte (1)

William Rose
William Rose il 10 Gen 2024
Make a single variable Vstat with three categories: LOW, MED, HIGH, rather than three separate variables.
load CHRX.mat % loads as CH = Chelsea; RX = Roxbury
Phi = prctile(CH.VLFN, 75);
Plo = prctile(CH.VLFN, 25);
[Vstat{1:height(CH),1}]=deal('MED'); % initialize Vstat
for i=1:height(CH)
if CH.VLFN(i)<Plo, Vstat{i}='LOW';
elseif CH.VLFN(i)>Phi, Vstat{i}='HIGH';
end
end
data=addvars(CH,Vstat); % Chelsea
%% HEATMAPS
% note: ImpactWind is the GROUP categorical variable (n=4)
% note: UFPConc is the OUTCOME, continuous variable or ColorVariable
format shortG
figure()
h = heatmap(data,'ImpactWind','Vstat','ColorVariable','UFPConc');
h.YDisplayLabels = {'HIGH','MED','LOW'};
There's probably a more elegant way to do it than the for loop I use below, but my way seems to work. Good luck.

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Tag

Prodotti


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by