<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/push-it-to-the-limit-som-clustering-networks/"></div></div><div><a data-url="http://www.r-bloggers.com/push-it-to-the-limit-som-clustering-networks/" data-counturl="http://www.r-bloggers.com/push-it-to-the-limit-som-clustering-networks/" data-count="horizontal" data-text="Push it to the limit: SOM + Clustering + Networks" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://imdevsoftware.wordpress.com/2016/05/19/push-it-to-the-limit-som-clustering-networks/"> r-bloggers – Creative Data Solutions</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><span><br>
What is the highest dimensional visualization you can think of? Now imagine it being interactive. The following details a Frankenstein visualization packing a smorgasbord of multivariate goodness.<br>
</span></p>
<p><span><img alt="composite2" class="wp-image-1406" src="https://imdevsoftware.files.wordpress.com/2016/04/composite2.png?w=590"><br>
Enter first, self-organizing maps (SOM). I first fell into a love dream with SOMs after using the <a target="_blank" href="https://cran.r-project.org/web/packages/kohonen/index.html">kohonen package</a>. The  wines data set example is a beautiful display of information.<br>
</span><br>
<img height="482" alt="og" width="423" class="wp-image-1283" src="https://imdevsoftware.files.wordpress.com/2016/04/og3.png?w=423&h=482"><br>
<span><br>
Eloquently, <a target="_blank" href="https://gist.github.com/dgrapov/f67d0696c4fb02731f55da3e1b9e8c4d">making the visualization</a> above is relatively easy. SOM is used to organize the data into related groups on a grid. Hierarchical cluster analysis (HCA) is used to classify the SOM codes into three groups.<br>
</span><br>
<img alt="clusters" class="wp-image-1270" src="https://imdevsoftware.files.wordpress.com/2016/04/clusters.png?w=590"></p>
<p><span><br>
HCA cluster information is mapped to the SOM grid using hexagon background colors. The radial bar plots show the variable (wine compounds’) patterns for samples (wines).<br>
</span><br>
<img alt="radial" class="wp-image-1275" src="https://imdevsoftware.files.wordpress.com/2016/04/radial.png?w=590"></p>
<p> </p>
<p><span><br>
The goal for this project was to reproduce the kohonen.plot using ggplot2 and make it interactive using shiny.<br>
</span><br>
<img alt="som1" class="wp-image-1311" src="https://imdevsoftware.files.wordpress.com/2016/04/som11.png?w=590"></p>
<p><span><br>
The main idea was to use SOM to calculated the grid coordinates, geom_hexagon for the grid packing and any ggplot for the hexagon-inset sub plots. Some basic inset plots could be bar or line plots.<br>
</span></p>
<p>
<a target="_blank" href="https://imdevsoftware.wordpress.com/2016/05/19/push-it-to-the-limit-som-clustering-networks/bar-2/"><img data-image-description="" data-orig-file="https://imdevsoftware.files.wordpress.com/2016/04/bar.png" data-orig-size="902,448" width="150" data-image-title="bar" data-comments-opened="1" data-attachment-id="1269" height="75" alt="bar" data-medium-file="https://imdevsoftware.files.wordpress.com/2016/04/bar.png?w=300" data-large-file="https://imdevsoftware.files.wordpress.com/2016/04/bar.png?w=590" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://imdevsoftware.files.wordpress.com/2016/04/bar.png?w=150&h=75"></a><br>
<a target="_blank" href="https://imdevsoftware.wordpress.com/2016/05/19/push-it-to-the-limit-som-clustering-networks/line/"><img data-image-description="" data-orig-file="https://imdevsoftware.files.wordpress.com/2016/04/line.png" data-orig-size="901,449" width="150" data-image-title="line" data-comments-opened="1" data-attachment-id="1271" height="75" alt="line" data-medium-file="https://imdevsoftware.files.wordpress.com/2016/04/line.png?w=300" data-large-file="https://imdevsoftware.files.wordpress.com/2016/04/line.png?w=590" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://imdevsoftware.files.wordpress.com/2016/04/line.png?w=150&h=75"></a><br>
<br>
<span><br>
Part of the beauty is the organization of any ggplot you cant think of (optionally grouping the input data or SOM codes) based on the SOM unit classification.<br>
<span><br>
A Pavlovian response might be; does it network?<br>
</span><br>
<img alt="network" class="wp-image-1272" src="https://imdevsoftware.files.wordpress.com/2016/04/network.png?w=590"><br>
<span><br>
Yes we can (network). Above is an example of different correlation patterns between wine components in related groups of wines. For example the green grid points identify wines showing a correlation between phenols and flavanoids (probably reds?). Their distance from each other could be explained (?) by the small grid size (see below).<br>
</span><br>
<span><br>
The next question might be, does it scale?<br>
</span><br>
<img alt="multi" class="wp-image-1352" src="https://imdevsoftware.files.wordpress.com/2016/04/multi.png?w=590"></span></p>
<p><img alt="more lines" class="wp-image-1354" src="https://imdevsoftware.files.wordpress.com/2016/04/more-lines.png?w=590"></p>
<p><span>There is potential. The 4 x 4 grid shows radial bar plot patterns for 16 sub groups among the 3 larger sample groups. The next next 6 x 6 plot shows wine compound profiles for 36 ~related subsets of wines.</span><br>
<span><br>
A useful side effect is that we can use SOM quality metrics to give us an extra-dimensional view into tuning the visualization. For example we can visualize the number of samples per grid point or distances between grid points (dissimilarity in patterns).<br>
</span><br>
<span><br>
This is useful to identify parts of the somClustPlot showing the number of mapped samples and greatest differences.<br>
</span></p>
<p><a target="_blank" href="https://imdevsoftware.wordpress.com/2016/05/19/push-it-to-the-limit-som-clustering-networks/counts/"><img data-image-description="" data-orig-file="https://imdevsoftware.files.wordpress.com/2016/04/counts.png" data-orig-size="580,457" width="150" data-image-title="counts" data-comments-opened="1" data-attachment-id="1393" height="118" alt="counts" data-medium-file="https://imdevsoftware.files.wordpress.com/2016/04/counts.png?w=300" data-large-file="https://imdevsoftware.files.wordpress.com/2016/04/counts.png?w=580" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://imdevsoftware.files.wordpress.com/2016/04/counts.png?w=150&h=118"></a><br>
<a target="_blank" href="https://imdevsoftware.wordpress.com/2016/05/19/push-it-to-the-limit-som-clustering-networks/diagnostics/"><img data-image-description="" data-orig-file="https://imdevsoftware.files.wordpress.com/2016/04/diagnostics1.png" data-orig-size="580,445" width="150" data-image-title="diagnostics" data-comments-opened="1" data-attachment-id="1398" height="115" alt="diagnostics" data-medium-file="https://imdevsoftware.files.wordpress.com/2016/04/diagnostics1.png?w=300" data-large-file="https://imdevsoftware.files.wordpress.com/2016/04/diagnostics1.png?w=580" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://imdevsoftware.files.wordpress.com/2016/04/diagnostics1.png?w=150&h=115"></a></p>
<p><span><br>
One problem I experienced was getting the hexagon packing just right. I ended making controls to move the hexagons  ~up/down and zoom in/out on the plot. It is not perfect but shows potential (?) for scaffolding highly multivariate visualizations? Some of my other concerns include the stochastic nature of SOM and the need for som random initialization for the embedding. Make sure to use it with set.seed() to make it reproducible, and might want to try a few seeds. Maybe someone out there knows how to make this aspect of  SOM more robust?<br>
</span></p>
<p><img height="1" alt="" width="1" src="https://pixel.wp.com/b.gif?host=imdevsoftware.wordpress.com&blog=38119978&%23038;post=1245&%23038;subd=imdevsoftware&%23038;ref=&%23038;feed=1" border="0"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-layout="box_count" data-send="true" data-height="62" data-href="http://www.r-bloggers.com/push-it-to-the-limit-som-clustering-networks/"></div></div><div><a data-url="http://www.r-bloggers.com/push-it-to-the-limit-som-clustering-networks/" data-counturl="http://www.r-bloggers.com/push-it-to-the-limit-som-clustering-networks/" data-count="vertical" data-text="Push it to the limit: SOM + Clustering + Networks" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://imdevsoftware.wordpress.com/2016/05/19/push-it-to-the-limit-som-clustering-networks/"> r-bloggers – Creative Data Solutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/Ks1baoSQM14"></a></div>