# Understanding distribution plots

### Why are distribution plots important?&#x20;

When working with large datasets in biomedical research, it is vital to understand the structure of your dataset to inform downstream processes and analyses. Distribution plots provide information like correlation scores, variable distributions and pairwise data spread, which can inform data cleaning processes and analyses such as:

* Remove highly correlated features that may carry redundant information and cause multicollinearity in linear analyses or motivate use of dimensionality reduction. &#x20;
* Determine predictive power of features to be used for supervised learning through correlation score&#x20;
* Apply transformations or scaling for data columns that are heavily skewed or have significant noise or outliers&#x20;
* Choose non-parametric models if the data does not appear to follow a normal distribution&#x20;

### What do PANDORA's distribution plots show?&#x20;

Generally, the distribution plot consists of three parts:&#x20;

1. **Diagonal**: Distributions of each variable as density plots
2. **Lower Triangle**: Pairwise scatterplots between two variables with trend lines
3. **Upper Triangle**: Correlation coefficients, showing how each variable varies with the other&#x20;

<figure><img src="https://1845146574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZMrkCA3Bqd62Gp0kAk79%2Fuploads%2FGpvB7Yg5po2BuuBdvvaq%2FAsset%201.png?alt=media&#x26;token=9c509d71-3937-4190-849d-7f062bf0c7aa" alt=""><figcaption></figcaption></figure>

This can be showcased using numerical variables from the COVID Pitch dataset (`covid_pitch.csv` from [Introduction](https://atomic-lab.gitbook.io/pandora/example-workflows/example-2-sars-cov-2-infection/introduction)) such as days post onset of SARS-CoV-2 symptoms (`Days pso`), T and B cells ELISpots (`Total pos T cells elispot`, `B cells elispot`), and concentrations of various immunoglobin types (`S-IgA memB SARS-CoV-2`, `S-IgG`)

<figure><img src="https://1845146574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZMrkCA3Bqd62Gp0kAk79%2Fuploads%2FCTeDRl2e0186pbA7NGGn%2Fdata%20overview%20continuous%20var%20distribution%20plot.png?alt=media&#x26;token=8e024622-643f-4daa-a756-8e21b5344085" alt=""><figcaption></figcaption></figure>

### How is the distribution plot different with categorical variables?&#x20;

To illustrate the differences, we produce a plot with a mix of categorical variables (such as severity of SARS-CoV-2 disease symptoms, `Disease severity`, outcome of immune response durability at 6 months, `Responder`, and gender of participants, `sex`) and numerical variables (such as `Donor ID` and disease symptom `Change or loss of taste`)&#x20;

Looking at the three subparts of the distribution plot:&#x20;

1. **Diagonal**: Instead of density plots, categorical variables will have **histograms** that show the distribution of each category&#x20;
2. **Lower triangle**: As there cannot be pairwise scatterplots produced between categorical-categorical variables or between categorical-numerical variables, we observe only one scatterplot between the two numerical variables `Change or loss of taste` and `Donor ID`.&#x20;

{% hint style="info" %}
Since the pairwise scatterplot between `Donor ID` and `Change or loss of taste` shows points at the top or bottom of the graph, and the density plot of `Change or loss` of taste is bimodal, `Change or loss` must have **binary values.**&#x20;
{% endhint %}

1. **Upper triangle**: The outputs in the upper triangle vary by the variable types being compared. Each possible output by variable type comparison is described below:
   1. **Numerical to numerical:** [Pearson's r correlation coefficient](#user-content-fn-1)[^1] is displayed here, as it can only be calculated for comparisons between numerical variables. A star next to the number indicates there is a significant linear relationship between the variables
      1. In this example, we observe only one correlation coefficient between the two numerical variables `Change or loss of taste` and `Donor ID`.
   2. **Numerical to categorical:** Boxplots[^2] are produced to show how the numerical variables vary among different categories within the categorical variable (as highlighted by the red boxes in the image below)
   3. **Categorical to categorical:** [Mosaic plots](#user-content-fn-3)[^3] are produced to show how the categories within a categorical variable vary with respect to categories in another categorical variable (as highlighted by the green boxes below)&#x20;

<figure><img src="https://1845146574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZMrkCA3Bqd62Gp0kAk79%2Fuploads%2FGVaymVXvCJVbkQN4qGoU%2FScreenshot%202025-06-19%20135537.png?alt=media&#x26;token=eb6b9cb5-470c-4e52-aea2-1adf5d527613" alt=""><figcaption></figcaption></figure>

### How to read these plots?&#x20;

1. **Boxplot**: This plot shows the spread of the values within the numerical variable for each category of the categorical variable. For example, the two box plots in the box in row 1, column 2 show the spread of the timepoints based on high or low responder status. The spread is showcased through several parts:
   1. **Median**: The line in middle of the box
   2. **The box**: Interquartile range (IQR) showing the data between the first quartile (25 percentile) and third quartile (75 percentile)&#x20;
   3. **Whiskers**: The bottom whisker consists of the first quartile of data and the end of the line indicates the *minimum* value. The top whisker consists of the fourth quartile of data and the end of the line indicates the *maximum* value
2. **Mosaic plots**: This plot shows the number of samples for each permutation of the categories present within the two categorical variables by the size of the box.&#x20;

   1. Example: Let us look at the plot between Disease severity and Responder in the image below (row 2, column 3)&#x20;

   <figure><img src="https://1845146574-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZMrkCA3Bqd62Gp0kAk79%2Fuploads%2FyHIf0ctqKj2pi4ITGhTw%2FAsset%203.png?alt=media&#x26;token=dbf62a3c-1f99-440a-8cf0-0bb7021b25a9" alt=""><figcaption></figcaption></figure>

   1. As shown in the image above, `Disease severity` is split into 'asymptomatic' and 'mild', while `Responder` is split into 'high' and 'low'.&#x20;
   2. As we label the categories accordingly, we can see that&#x20;
      1. More high responders had mild disease severity compared to being asymptomatic, as seen by the notable difference in the size of the top bars&#x20;
      2. Slightly more low responders had mild disease severity compared to being asymptomatic, as seen with the less drastic difference in the size of the bottom bars.&#x20;

[^1]: A statistical measure for the direction and strength of a linear relationship between two numerical continuous variables.

[^2]: Graphically shows the five number summary of the numerical variable's values associated with each category of the categorical variable.

[^3]: A visual representation of a contingency table that shows the joint distribution of two categorical variables.
