My original data
is a 195x22
record set containing vocal measurements of people having Parkinson's disease or not. In a vector, 195x1
, I have a status
which is either 1/0.
Now, I have performed a PCA and I do a biplot
, which turns out well. The problem is that I can't tell which dots from my scatter plot origin of a sick or a healthy person (I can't link it with status
). I would like for my scatter plot to have a red dot if healthy (status=0) and green if sick (status=1).
How would I do that? My biplot code is:
biplot(coeff(:,1:2), ...
'Scores', score(:,1:2), ...
'VarLabels', Labels, ...
'markersize', 15 ...
);
xlabel('Bi-Plot: Standardized Data');
xlabel('PCA1');
ylabel('PCA2');
UPDATE (Solution):
Solution is inspired by @Magla and code can be seen here: http://pastebin.com/KHUj3DnA
With this beautiful graph:

The principal component scores (red points) in a biplot
are not the ones returned by the pca
function. As the help states,
biplot scales the scores so that they fit on the plot: It divides each score by the maximum absolute value of all scores, and multiplies by the maximum coefficient length of coefs. Then biplot changes the sign of score coordinates according to the sign convention for the coefs.
You therefore can't easily use the (X,Y)
information to find out which point belong to a category.
Here is a workaround using the ObsLabels
option of biplot
. ObsLabels
assigns some user-defined data to each observation: for each point, we will assign the index corresponding to a status
variable (a simple incrementing value). With this, you can easily modify the red points of a biplot
- here marker
set to square and red/green color.
The following figure

is produced by this code
%some data
load carsmall
x = [Acceleration Displacement Horsepower MPG Weight]; x = x(all(~isnan(x),2),:);
[coefs,score] = pca(zscore(x));
%the status vector (here zero or one)
class_pt = round(rand(size(score,1),1));
vbls = {'Accel','Disp','HP','MPG','Wgt'};
figure('Color', 'w');
hbi = biplot(coefs(:,1:2),'scores',score(:,1:2),'varlabels',vbls,...
'ObsLabels',num2str((1:size(score,1))'));
for ii = 1:length(hbi)
userdata = get(hbi(ii), 'UserData');
if ~isempty(userdata)
if class_pt(userdata) == 0
set(hbi(ii), 'Color', 'g', 'Marker', 's');
elseif class_pt(userdata) == 1
set(hbi(ii), 'Color', 'r', 'Marker', 's');
end
end
end
来源:https://stackoverflow.com/questions/19052317/configuring-biplot-in-matlab-to-distinguish-in-scatter