load('data.mat')
[coeff,score,latent,tsquared,explained] = pca(X);
f1=figure();
h= biplot(coeff(:,1:2),'scores',score(:,1:2),'color','k','marker','.','markersize',17,'varlabels',...
{'DO','O2sat','pH','Temp','Sal','Depth','PAR','|Velocity|'});
hold on
hID = get(h,'tag');
hPt = h(strcmp(hID,'obsmarker'));
[grp, grpID] = findgroups(site);
clrMap = winter(numel(grpID));
p = 95;
for i = 1:max(grpID)
set(hPt(grp==i), 'Color', clrMap(i,:), 'DisplayName', sprintf('MSP%d', grpID(i)))
allX = arrayfun(@(hh)hh.XData(1), hPt(grp==i));
allY = arrayfun(@(hh)hh.YData(1), hPt(grp==i));
centers(1) = mean(allX);
centers(2) = mean(allY);
plot(centers(1), centers(2), 'rp', 'MarkerFaceColor', clrMap(i,:), 'MarkerSize', 20, 'LineWidth', 1)
CIx = prctile(allX, [(100-p)/2, p+(100-p)/2]);
CIy = prctile(allY, [(100-p)/2, p+(100-p)/2]);
CIrng(1) = CIx(2)-CIx(1);
CIrng(2) = CIy(2)-CIy(1);
llc = [CIx(1), CIy(1)];
rectangle('Position',[llc,CIrng],'Curvature',[1,1], 'EdgeColor', clrMap(i,:));
end
title('Full Deployment (12h)');
set(gca,'fontsize',18)
xlabel('Component 1 (55.26%)')
ylabel('Component 2 (21.87%)')
[~, unqIdx] = unique(grp);
legend(hPt(unqIdx))
Best Answer