layout: true <div class="my-footer"><span>R Course 20-21 Sep 2018, CCP</span></div> --- # What is a heatmap? -- .pull-left[ <table> <thead> <tr> <th style="text-align:left;"> </th> <th style="text-align:right;"> 1 </th> <th style="text-align:right;"> 2 </th> <th style="text-align:right;"> 3 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> A </td> <td style="text-align:right;"> 1.3709584 </td> <td style="text-align:right;"> -0.0946590 </td> <td style="text-align:right;"> -0.1333213 </td> </tr> <tr> <td style="text-align:left;"> B </td> <td style="text-align:right;"> -0.5646982 </td> <td style="text-align:right;"> 2.0184237 </td> <td style="text-align:right;"> 0.6359504 </td> </tr> <tr> <td style="text-align:left;"> C </td> <td style="text-align:right;"> 0.3631284 </td> <td style="text-align:right;"> -0.0627141 </td> <td style="text-align:right;"> -0.2842529 </td> </tr> <tr> <td style="text-align:left;"> D </td> <td style="text-align:right;"> 0.6328626 </td> <td style="text-align:right;"> 1.3048697 </td> <td style="text-align:right;"> -2.6564554 </td> </tr> <tr> <td style="text-align:left;"> E </td> <td style="text-align:right;"> 0.4042683 </td> <td style="text-align:right;"> 2.2866454 </td> <td style="text-align:right;"> -2.4404669 </td> </tr> <tr> <td style="text-align:left;"> F </td> <td style="text-align:right;"> -0.1061245 </td> <td style="text-align:right;"> -1.3888607 </td> <td style="text-align:right;"> 1.3201133 </td> </tr> <tr> <td style="text-align:left;"> G </td> <td style="text-align:right;"> 1.5115220 </td> <td style="text-align:right;"> -0.2787888 </td> <td style="text-align:right;"> -0.3066386 </td> </tr> </tbody> </table> ### Can you spot the lowest value? ] -- .pull-right[ ![](heatmaps_slides_files/figure-html/mat2-1.png)<!-- --> ] --- ## What is a heatmap? ![](./heatmaps_slides_files/usa.gif) --- ## What is a heatmap? <img src="./heatmaps_slides_files/plos.png", width=70%> image source: [https://doi.org/10.1371/journal.pone.0007399.g004](https://doi.org/10.1371/journal.pone.0007399.g004) --- ## Data <table class="table table-striped table-hover table-condensed" style="font-size: 10px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:right;"> Number </th> <th style="text-align:left;"> Chocolate </th> <th style="text-align:right;"> TK </th> <th style="text-align:right;"> LS </th> <th style="text-align:right;"> MT </th> <th style="text-align:right;"> KF </th> <th style="text-align:right;"> MM </th> <th style="text-align:right;"> ToKo </th> <th style="text-align:right;"> JDZ </th> <th style="text-align:right;"> JDH </th> <th style="text-align:right;"> LuS </th> <th style="text-align:right;"> PK </th> <th style="text-align:right;"> KA </th> <th style="text-align:left;"> Cocoa </th> <th style="text-align:left;"> Type </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> 1 </td> <td style="text-align:left;"> Kaffeesplitter </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 1 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 8 </td> <td style="text-align:right;"> 1 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> NA </td> <td style="text-align:right;"> 5 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:left;"> Dark </td> <td style="text-align:left;"> Crispy </td> </tr> <tr> <td style="text-align:right;"> 2 </td> <td style="text-align:left;"> Schoko-Brownie </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 5 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> Milk </td> <td style="text-align:left;"> Creme </td> </tr> <tr> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> Karamell-mousse </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> NA </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> Milk </td> <td style="text-align:left;"> Creme </td> </tr> <tr> <td style="text-align:right;"> 4 </td> <td style="text-align:left;"> Alpenmilch </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 5 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 1 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> Milk </td> <td style="text-align:left;"> Pure </td> </tr> <tr> <td style="text-align:right;"> 5 </td> <td style="text-align:left;"> Edel-Bitter </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 1 </td> <td style="text-align:right;"> 1 </td> <td style="text-align:right;"> 8 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:left;"> Dark </td> <td style="text-align:left;"> Pure </td> </tr> <tr> <td style="text-align:right;"> 6 </td> <td style="text-align:left;"> Edel-Vollmilch </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> Milk </td> <td style="text-align:left;"> Pure </td> </tr> <tr> <td style="text-align:right;"> 7 </td> <td style="text-align:left;"> Erdbeer-Joghurt </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 8 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 7 </td> <td style="text-align:right;"> NA </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:left;"> Milk </td> <td style="text-align:left;"> Fruits </td> </tr> <tr> <td style="text-align:right;"> 8 </td> <td style="text-align:left;"> Halb-Bitter </td> <td style="text-align:right;"> 5 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 5 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 1 </td> <td style="text-align:right;"> NA </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> Dark </td> <td style="text-align:left;"> Pure </td> </tr> <tr> <td style="text-align:right;"> 9 </td> <td style="text-align:left;"> Kakao-mousse </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 5 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:left;"> Milk </td> <td style="text-align:left;"> Creme </td> </tr> <tr> <td style="text-align:right;"> 10 </td> <td style="text-align:left;"> Knusperkeks </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 5 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 2 </td> <td style="text-align:right;"> 3 </td> <td style="text-align:left;"> Milk </td> <td style="text-align:left;"> Crispy </td> </tr> </tbody> </table> --- ## Data .pull-left[ ![](heatmaps_slides_files/figure-html/unnamed-chunk-2-1.png)<!-- --> ] --- ## Data .pull-left[ ![](heatmaps_slides_files/figure-html/box-1.png)<!-- --> ] .pull-right[ ### Scale? - The differences between the features outweighs differences between samples Z-score normalization `$$z_i=\frac{x_i -\mu}{\sigma}$$` - What are you interested in? [(Link)](http://www.opiniomics.org/you-probably-dont-understand-heatmaps/) ] --- ## Data .pull-left[ ![](heatmaps_slides_files/figure-html/unnamed-chunk-3-1.png)<!-- --> ] .pull-right[ ### Scale? - The differences between the features outweighs differences between samples Z-score normalization `$$z_i=\frac{x_i -\mu}{\sigma}$$` - What are you interested in? [(Link)](http://www.opiniomics.org/you-probably-dont-understand-heatmaps/) ] --- ## Data .pull-left[ ![](heatmaps_slides_files/figure-html/unnamed-chunk-4-1.png)<!-- --> ] -- .pull-right[ ### Can you see groups? ] --- ## Heatmap clustering .pull-left[ ![](heatmaps_slides_files/figure-html/unnamed-chunk-5-1.png)<!-- --> ] .pull-right[ How does it work: [(Wiki)](https://en.wikipedia.org/wiki/Hierarchical_clustering#Agglomerative_clustering_example) ] --- ## Plotting heatmaps in R - [heatmap](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/heatmap.html) - heatmap.2 ([gplots package](https://cran.r-project.org/web/packages/gplots/index.html)) - [pheatmap](https://cran.r-project.org/web/packages/pheatmap/index.html) - [ComplexHeatmap](https://github.com/jokergoo/ComplexHeatmap) - [d3heatmap](https://cran.r-project.org/package=d3heatmap) - [heatmaply](https://cran.r-project.org/web/packages/heatmaply/index.html) and many more.