- Plot Points on PC1: Use the score output from PCA, which contains the coordinates in the principal component space. The first column is your projection onto PC1.
- Visualize Eigenvectors: The coeff matrix contains eigenvectors. Plot these as arrows using the mean of your data as the origin. Normalize these vectors if you want to emphasize direction over magnitude.
- PCA vs. SVD: For your purpose, PCA is sufficient. It provides the principal components and their eigenvectors, which is what you need for visualization.
Generating a plot of showing points directed towards PC1
5 views (last 30 days)
Show older comments
I have a data set (attached) where the columns are the ID, X, Y, and Z coordinate values. I have run the principal component function (pca) on the data. I want to plot the points along PC1 only and show the eigen vectors of each point as arrows directed towards the PC1 line. Can anyone recommend the best way to generate a plot like this? Do I need to normalize the eigen values? Is it better to run signle value decomposition (SVD) instead of PCA?
[coeff,score,latent,tsquared,explained,mu] = pca(Data(:,[2 3 4]))
0 Comments
Answers (1)
Hornett
on 18 Sep 2024
Hi Stephen
To plot your data points along the first principal component (PC1) and show eigenvectors as arrows directed towards the PC1 line, follow these steps:
% Assuming PCA has been run and you have coeff, score, and mu
figure;
plot(score(:,1), zeros(size(score(:,1))), 'bo'); % Points on PC1
hold on;
% Eigenvectors as arrows from data mean
quiver(mu(1)*ones(1,3), mu(2)*ones(1,3), coeff(1,:), coeff(2,:), 0.5, 'k');
xlabel('PC1');
title('Projection onto PC1 with Eigenvectors');
axis equal;
grid on;
hold off;
This code plots data points along PC1 and draws eigenvectors as arrows. Adjust the quiver function's scaling factor as needed for clear visualization.
0 Comments
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!