Skip to content

Commit

Permalink
Render toc-less
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 10, 2024
1 parent a68fa9e commit b7cac6c
Show file tree
Hide file tree
Showing 29 changed files with 31 additions and 31 deletions.
30 changes: 15 additions & 15 deletions docs/no_toc/05-data-visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ To create a histogram, we use the function [`sns.displot()`](https://seaborn.pyd


``` python
sns.displot(data=metadata, x="Age")
plot = sns.displot(data=metadata, x="Age")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-3-1.png" width="244" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-3-2.png" width="480" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-3-1.png" width="480" />

A common parameter to consider when making histogram is how big the bins are. You can specify the bin width via `binwidth` argument, or the number of bins via `bins` argument.

Expand All @@ -68,7 +68,7 @@ A common parameter to consider when making histogram is how big the bins are. Yo
sns.displot(data=metadata, x="Age", binwidth = 10)
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-4-5.png" width="244" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-4-6.png" width="480" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-4-3.png" width="244" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-4-4.png" width="480" />

Our histogram also works for categorical variables, such as "Sex".

Expand All @@ -77,7 +77,7 @@ Our histogram also works for categorical variables, such as "Sex".
sns.displot(data=metadata, x="Sex")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-5-9.png" width="244" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-5-10.png" width="480" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-5-7.png" width="244" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-5-8.png" width="480" />

**Conditioning on other variables**

Expand All @@ -88,7 +88,7 @@ Sometimes, you want to examine a distribution, such as Age, conditional on other
sns.displot(data=metadata, x="Age", hue="Sex")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-6-13.png" width="306" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-6-14.png" width="590" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-6-11.png" width="306" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-6-12.png" width="590" />

It is rather hard to tell the groups apart from the coloring. So, we add a new option that we want to separate each bar category via `multiple="dodge"` input argument:

Expand All @@ -97,7 +97,7 @@ It is rather hard to tell the groups apart from the coloring. So, we add a new o
sns.displot(data=metadata, x="Age", hue="Sex", multiple="dodge")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-7-17.png" width="306" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-7-18.png" width="590" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-7-15.png" width="306" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-7-16.png" width="590" />

Lastly, an alternative to using colors to display the conditional variable, we could make a subplot for each conditional variable's value via `col="Sex"` or `row="Sex"`:

Expand All @@ -106,7 +106,7 @@ Lastly, an alternative to using colors to display the conditional variable, we c
sns.displot(data=metadata, x="Age", col="Sex")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-8-21.png" width="745" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-8-22.png" width="1440" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-8-19.png" width="745" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-8-20.png" width="1440" />

You can find a lot more details about distributions and histograms in [the Seaborn tutorial](https://seaborn.pydata.org/tutorial/distributions.html).

Expand All @@ -119,7 +119,7 @@ To visualize two continuous variables, it is common to use a scatterplot or a li
sns.relplot(data=expression, x="KRAS_Exp", y="EGFR_Exp")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-9-25.png" width="244" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-9-26.png" width="480" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-9-23.png" width="244" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-9-24.png" width="480" />

To conditional on other variables, plotting features are used to distinguish conditional variable values:

Expand All @@ -138,7 +138,7 @@ expression_metadata = expression.merge(metadata)
sns.relplot(data=expression_metadata, x="KRAS_Exp", y="EGFR_Exp", hue="PrimaryOrMetastasis")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-10-29.png" width="317" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-10-30.png" width="629" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-10-27.png" width="317" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-10-28.png" width="629" />

Here is the scatterplot with different shapes:

Expand All @@ -147,7 +147,7 @@ Here is the scatterplot with different shapes:
sns.relplot(data=expression_metadata, x="KRAS_Exp", y="EGFR_Exp", style="PrimaryOrMetastasis")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-11-33.png" width="317" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-11-34.png" width="629" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-11-31.png" width="317" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-11-32.png" width="629" />

You can also try plotting with `size=PrimaryOrMetastasis"` if you like. None of these seem pretty effective at distinguishing the two groups, so we will try subplot faceting as we did for the histogram:

Expand All @@ -156,7 +156,7 @@ You can also try plotting with `size=PrimaryOrMetastasis"` if you like. None of
sns.relplot(data=expression_metadata, x="KRAS_Exp", y="EGFR_Exp", col="PrimaryOrMetastasis")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-12-37.png" width="744" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-12-38.png" width="1440" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-12-35.png" width="744" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-12-36.png" width="1440" />

You can also conditional on multiple variables by assigning a different variable to the conditioning options:

Expand All @@ -165,7 +165,7 @@ You can also conditional on multiple variables by assigning a different variable
sns.relplot(data=expression_metadata, x="KRAS_Exp", y="EGFR_Exp", hue="PrimaryOrMetastasis", col="AgeCategory")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-13-41.png" width="1074" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-13-42.png" width="2069" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-13-39.png" width="1074" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-13-40.png" width="2069" />

You can find a lot more details about relational plots such as scatterplots and lineplots [in the Seaborn tutorial](https://seaborn.pydata.org/tutorial/relational.html).

Expand Down Expand Up @@ -203,7 +203,7 @@ exp_plot = sns.relplot(data=expression, x="KRAS_Exp", y="EGFR_Exp")
exp_plot.set(xlabel="KRAS Espression", ylabel="EGFR Expression", title="Gene expression relationship")
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-14-45.png" width="244" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-14-46.png" width="480" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-14-43.png" width="244" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-14-44.png" width="480" />

You can change the color palette by setting adding the `palette` input argument to any of the plots. You can explore available color palettes [here](https://www.practicalpythonfordatascience.com/ap_seaborn_palette):

Expand All @@ -213,7 +213,7 @@ sns.displot(data=metadata, x="Age", hue="Sex", multiple="dodge", palette=sns.col
)
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-15-49.png" width="306" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-15-50.png" width="590" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-15-47.png" width="306" /><img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-15-48.png" width="590" />

## Exercises

Expand All @@ -224,7 +224,7 @@ Exercise for week 5 can be found [here](https://colab.research.google.com/drive/
hist(iris$Sepal.Length)
```

<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-16-53.png" width="672" />
<img src="resources/images/05-data-visualization_files/figure-html/unnamed-chunk-16-51.png" width="672" />


``` r
Expand Down
Loading

0 comments on commit b7cac6c

Please sign in to comment.