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

3 次查看(过去 30 天)
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

回答(3 个)

Matt Tearle
Matt Tearle 2011-2-26
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 个评论
Pergus
Pergus 2011-2-26
Thank you.
I am using version 7.0(14). Although Statistics Toolbox is installed, "dataset" and "nominal" functions are undefined.
Matt Tearle
Matt Tearle 2011-2-26
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.

请先登录,再进行评论。


Paulo Silva
Paulo Silva 2011-2-26
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 2011-2-28
[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.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by