Plot boxplot/boxchart outliers in different colors by goups

Hello community,
I´m running out of ideas on how to handle this problem. I have a table with 91 columns. The first 88 columns are features and and the last 3 are labels for this features. One of the three label columns tells, if the sample is considered sick or not. So I want to have a boxchart/boxplot which shows me the boxplot for each of this 88 features and color the outliers by their label, if they are sick or not.
All I get is this boxchart atm.
and my tbale looks like this
Here is a subset of the table. Only with path_1 and path_2 as columns and the labels column

5 comentarios

We can do essentially nothing w/o data -- and it's asking a lot for somebody to also make up a data set to try to match a problem...
Attach a small subset of the data; there's no difference in code logic between 2-3 variables and 90-some...
Sorry, I attached a sub set of the data in this post. I just took two columns and the labels to make it easier.
Besides that, the problem is that, I don´t know the code logic even for 2-3 variables.
Well, I dunno otomh that you can do what you're asking for or not, either, but gotta have data to try with for starters...
As I wrote. A subtable is provided in the post now
dpb
dpb el 23 de Sept. de 2022
Editada: dpb el 23 de Sept. de 2022
I was just agreeing/acknowledging...
A very quick perusal of boxplot wasn't much promising...I'm guessing you'll have to add the additional info onto the basic boxplot -- and how friendly it is to such shenanigans I don't know; I've not really tried much in that vein.

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 24 de Sept. de 2022
Editada: dpb el 25 de Sept. de 2022
fn=websave('sub_table.mat','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1134300/sub_table.mat');
load(fn)
isO=isoutlier(sub_table{:,1:end-1},"quartiles"); % outlier logical address array
[~,ic]=ismember(sub_table.label,categories(sub_table.label)); % lookup index for outlier
C=[1 0 0; 0 1 0; 0 0 1]; % r,g,b color each type label; update as desired
hBX=boxchart(sub_table{:,1:end-1}); % draw base box chart
hold on % get ready to add on top of box chart
drawnow % needed to refresh visible result; not needed if at command line
hBX.NodeChildren(1).Visible='off'; % the hidden handle hides marker object (outliers)
hAx=gca; % get current axes handle
% iterate over each patient in table -- assumes only one label last column in index limits
for i=1:numel(sub_table.Properties.VariableNames(1:end-1))
x=repmat(hAx.XTick(i),sum(isO(:,i)),1); % need a vector of categorical type
y=sub_table{isO(:,i),i}; % and the outliers for the patient
clr=C(ic(isO(:,i)),:); % the color by label lookup function
hSC(i)=scatter(x,y,[],clr); % draw the colored outliers
end
% dummy up a legend by color code -- scatter is just one object each subject
hL=plot(nan(size(C)),'o'); % as many lines as labels
set(hL,{'Color'},mat2cell(C,[1 1 1],3)) % match colors
hLG=legend(hL,categories(sub_table.label)); % label names
box on
"Salt to suit" on color mapping, symbols, size -- I could not find the handles to the markers to be able to delete them; there is only one color property for them however, so something like the above appears to be about the only choice.
It would be nice to use the 'jitter' option to not have the outliers all in the one vertical line...this is incorporated in the boxchart but not so easy to do with the added scatter plot since the x-axis is categorical and so only allows the discrete categorical values. One would have to then put the scatter plot on a second axes or revert to a numeric x-axis on the original data instead.

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Preguntada:

el 23 de Sept. de 2022

Comentada:

el 27 de Sept. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by