# Run a PCA and plot it properly

> Upload a table of measurements. Yila standardises the variables, runs the principal component analysis and draws the score plot, the scree plot and a readable biplot, with the loadings and the script.

URL: https://yila.ai/playbooks/pca-plot

## What you get

- **Score plot** (PNG + SVG): PC1 against PC2 with the variance explained on each axis, points coloured by group and 95% confidence ellipses.
- **Scree plot** (PNG + SVG): Individual and cumulative variance explained per component, so you can justify how many components to keep.
- **Biplot and loadings** (Figure + CSV): Arrows for the variables that contribute most, plus the full loadings table for every component.
- **The script** (Python script): The complete analysis in Python (or R if you ask), with the preprocessing written out.

## How it works

1. **Upload the table and name the groups**: Give Yila a CSV or Excel file with the measurements and say which column to colour by. Groups are only used for colour, not for the PCA itself.
2. **Yila checks the variables and the scaling**: It looks at the units and ranges, standardises variables measured on different scales, and reports missing values before running the PCA.
3. **Get the three plots and the loadings**: Score plot, scree plot and biplot are rendered, checked and saved with the loadings and the script. Ask for PC1 against PC3, labels on points or a 3D view in the same conversation.

## Made for

- **Omics and metabolomics**: See whether samples cluster by treatment or batch before the differential analysis.
- **Chemistry and food science**: Show how samples separate on many measured properties at once, and which properties drive it.
- **Survey and questionnaire data**: Reduce many correlated items to a few components and see which items load together.

## Questions

### What does a PCA plot show?

Principal component analysis turns many correlated variables into a few uncorrelated components ordered by how much variance they explain. The score plot places each sample on the first two components, so samples that are alike overall sit close together.

### Should the variables be standardised?

When they are measured in different units or ranges, yes; otherwise the variable with the largest numbers dominates. In the example, proline runs into the hundreds and hue around 1, so all thirteen were standardised. For variables on one shared scale, Yila may leave them as they are and tell you why.

### How many components should I keep?

The scree plot and the cumulative variance help: common rules are the elbow of the curve, a target such as 80% of variance, or components with eigenvalues above 1. Yila reports these and leaves the choice to you.

### What do the confidence ellipses mean?

Each ellipse covers the region where 95% of a group's scores are expected under a bivariate normal assumption. They help show separation; they are not a statistical test.

### Can I use PCA to test whether groups differ?

No. PCA is descriptive. If the groups separate and you want a test, ask for PERMANOVA or a discriminant analysis and Yila adds it.

### R or Python?

Either. The example used Python with scikit-learn; in R, Yila uses prcomp with ggplot2 or factoextra.

### Where does the example data come from?

From the open Wine dataset (Aeberhard and Forina), published under CC BY 4.0 on the UCI Machine Learning Repository. Yila never uses users' data as examples.

---

- [Run a PCA and plot it properly](https://yila.ai/playbooks/pca-plot)
- [llms.txt](https://yila.ai/llms.txt)
