How can I group data and plot them with unique markers for each group?

3 views (last 30 days)
Hello,
Briefly, I would like to plot custom x-y plots (or scatters) of samples where symbols are chosen according to the sample type.
I have a dataset for over 800 samples with 50 variables for each, which makes 800x50 matrix held as structure (dataset.mat). Samples belong to ~ 40 categories. Sample names are held in "dataset.name" and categories are in "dataset.category"
I have a simple function which loads the dataset structure at the beginning and asks for the X and Y variables. X and Y are input by keyboard:
x=input ('X variables?');
y=input ('Y-variables?');
Once the variables have been set, a function (Marker.m) for plotting and chosing the symbols is called. Each category should have unique marker (or symbol). Marker function consists of a simple switch-case statement. It plots the samples with the same marker if they belong to the same category. Besides, sample names are very important so they must be displayed in Plot browser:
for i=length(dataset.name):-1:1
switch dataset.category
case 'Category_01'
plot (vx(i), vy(i),'x','DisplayName',dataset.name(i));
case 'Category_02'
plot (vx(i), vy(i),'o','DisplayName',dataset.name(i));
end
When I want some categories to be invisible, I "%, comment" the case statement in m-file. But as the dataset gets bigger everyday and number of categories increases, it becomes a real torture to comment and uncomment tens of lines in each run. Furthermore, Plot browser becomes a mess with tons of samples.
I am trying to group samples according to their categories. My aim is to see only categories in plot browser, where I can make them visible or invisible using checkboxes. And also to see sample names on Property editor when I click on the points.
I have tried hggroup but I couldn't make to see the sample names.
Any suggestions?
Thank you in advance
Pergus

Answers (3)

Matt Tearle
Matt Tearle on 26 Feb 2011
Given your description of the data and what you're trying to do with it, I'd say you really need Statistics Toolbox. Then use dataset arrays to store the data, with a nominal array for the category. There are many functions available for grouped data, including gscatter.
  2 Comments
Pergus
Pergus on 26 Feb 2011
Thank you.
I am using version 7.0(14). Although Statistics Toolbox is installed, "dataset" and "nominal" functions are undefined.
Matt Tearle
Matt Tearle on 26 Feb 2011
Ouch. OK... Assuming that upgrading isn't an option, how about a simple GUI, would that suffice? A plot window, with checkboxes for the categories. Then maybe a way to display the sample name when you click on it.

Sign in to comment.


Paulo Silva
Paulo Silva on 26 Feb 2011
Please share the dataset.mat so I can try to make a GUI for what you want, I love a good chalenge :)

Walter Roberson
Walter Roberson on 28 Feb 2011
[ucats, aidx, bidx] = unique(dataset.category);
ncats = length(ucats);
plothandles = cell(ncats,1);
for K = 1 : ncats
thiscat = ucats{K};
thismarker = ChooseMarker(thiscat);
theseentries = find(bidx == K);
nents = length(theseentries);
thesehandles = zeros(nents,1);
for P = 1 : nents
entnum - theseentries(P);
thesehandles(P) = plot(vx(entnum), vy(entnum), thismarker, 'DisplayName', dataset.names{entnum});
end
plothandles{K} = thesehandles;
end
After which, build the array of checkboxes with entries named according to ucats cell array, and with the callback for the box #Q set to turn plothandles{Q} 'Visible' property 'on' or 'off'.
Easy code, and more efficient than what you are doing now.

Community Treasure Hunt

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

Start Hunting!