How to give a color and a marker to points when using mapca() and biplot()?
Show older comments
I am doing PCA and using mapcaplot() in order to get the Principal Component Visualization tool. I am wondering if there is any way to color-code my different points. For example, I have variables, group A and group B, and I would like the points corresponding to each variable to be different colors. Can I also differentiate by shape? I have a second variable with group 1,2, and 3 and I would like each of these groups to be represented by a different shape.
Additionally, if it is not possible to do in the Principal Component Visualization tool, can I color-code my points when using biplot(coeff(:,1:2),'scores',score(:,1:2)) (which creates the graph of the values plotted against Component 1 and Component 2?)
Again, I would want to differentiate group A from group B by using 2 colors and group 1-3 by using different shapes.
Answers (1)
Prasanna
on 18 Jun 2024
0 votes
Hi Stephanie,
While the 'mapcaplot' function in MATLAB does not offer direct options to color-code or shape-code the points based on group membership, you can achieve similar visualization goals by using the 'biplot' function or by customizing your plots with lower-level plotting functions. The 'biplot' function allows for some customization, but if you need more control over the appearance of points, you might need to plot your PCA results manually using functions like 'plot', 'scatter', or 'gscatter'.
To achieve color and shape coding based on your group variables, you can use the 'gscatter' function or manually plot each group with different colors and shapes using the 'scatter' or 'plot' function with the corresponding 'score' variable.
For more reference on the graphing functions specified above, you can refer the following documentations:
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!