<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/interactive-volcano-plots-in-r-with-plotly/"></div></div><div><a data-url="https://www.r-bloggers.com/interactive-volcano-plots-in-r-with-plotly/" data-counturl="https://www.r-bloggers.com/interactive-volcano-plots-in-r-with-plotly/" data-count="horizontal" data-text="Interactive Volcano Plots in R with Plotly" 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="http://moderndata.plot.ly/interactive-volcano-plots-r-plotly/"> R – Modern Data</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h3>Introduction</h3>
<p>In a recent <a target="_blank" rel="nofollow" href="http://moderndata.plot.ly/manhattanly-r-package-for-interactive-manhattan-plots/">blog post</a>, I introduced the new R package, <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/manhattanly/">manhattanly</a>, which creates interactive manhattan and Q-Q plots using the <a target="_blank" rel="nofollow" href="https://plot.ly/">plotly.js</a> engine. In the latest <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/manhattanly/index.html">CRAN release</a>, you can also create volcano plots.</p>
<p>In this post, I describe how to create interactive volcano plots using the <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/manhattanly/">manhattanly</a> package. Volcano plots are the negative log10 p-values plotted against their effect size, odds ratio or log fold-change. They are used to identify clinically meaningful markers in genomic experiments, i.e., markers that are statistically significant and have an effect size greater than some threshold. </p>
<p>Visit the <a target="_blank" rel="nofollow" href="https://github.com/sahirbhatnagar/manhattanly">package website</a> for full details and example usage. </p>
<h3>Quick Start</h3>
<p>The following three lines of code will produce the Volcano plot below</p>

<pre>install.packages(&quot;manhattanly&quot;)
library(manhattanly)
volcanoly(HapMap, snp = &quot;SNP&quot;, gene = &quot;GENE&quot;)</pre>

<p><iframe height="800" width="900" src="http://plot.ly/~sahirbhatnagar/63.embed"></iframe></p>
<p>Notice that we have added two annotations (the SNP and nearest GENE), that are revealed when hovering the mouse over a point. This feature of interactive volcano plots adds a great deal of information to the plot without cluttering it with text. </p>
<h3>The Data</h3>
<p>Inspired by the <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/heatmaply/vignettes/heatmaply.html">heatmaply</a> package by <a target="_blank" rel="nofollow" href="http://www.r-statistics.com/">Tal Galili</a>, we split the tasks into data pre-processing and plot rendering. Therefore, we can use the <code>manhattanly::volcanor</code> function to get the data used to produce a volcano plot. This allows flexibility in the rendering of the plot, since any graphics package, such as <code>plot</code> in base R can make used to create the plot.</p>
<p>The plot data is derived using the <code>manhattanly::volcanor</code> function:</p>

<pre>volcanorObject &lt;- volcanor(HapMap, snp = &quot;SNP&quot;)
str(volcanorObject)</pre>

<p><code><br>
List of 8<br>
 $ data           :'data.frame':	14412 obs. of  4 variables:<br>
  ..$ EFFECTSIZE: num [1:14412] -0.0946 -0.0947 -0.0741 0.0146 0.1234 ...<br>
  ..$ P         : num [1:14412] 0.335 0.246 0.823 0.493 0.605 ...<br>
  ..$ SNP       : chr [1:14412] &quot;rs9697358&quot; &quot;rs34945898&quot; &quot;rs12034613&quot; &quot;rs4648633&quot; ...<br>
  ..$ LOG10P    : num [1:14412] 0.4745 0.6093 0.0844 0.307 0.218 ...<br>
 $ pName          : chr &quot;P&quot;<br>
 $ effectName     : chr &quot;EFFECTSIZE&quot;<br>
 $ xlabel         : chr &quot;EFFECTSIZE&quot;<br>
 $ snpName        : chr &quot;SNP&quot;<br>
 $ geneName       : logi NA<br>
 $ annotation1Name: logi NA<br>
 $ annotation2Name: logi NA<br>
 - attr(*, &quot;class&quot;)= chr &quot;volcanor&quot;<br>
</code> </p>

<pre>head(volcanorObject[[&quot;data&quot;]])</pre>

<p><code><br>
  EFFECTSIZE         P        SNP     LOG10P<br>
1    -0.0946 0.3353438  rs9697358 0.47450973<br>
2    -0.0947 0.2458571 rs34945898 0.60931719<br>
3    -0.0741 0.8232859 rs12034613 0.08444933<br>
4     0.0146 0.4932038  rs4648633 0.30697357<br>
5     0.1234 0.6053916  rs4430271 0.21796358<br>
6     0.1979 0.1944431  rs6685625 0.71120743<br>
</code></p>
<p>This <code>volcanorObject</code> which is of class <code>volcanor</code> can also be passed to the <code>manhattanly::volcanoly</code> function to produce the inteactive volcano plot above:</p>

<pre>volcanoly(volcanorObject)</pre>

<h3>Automatic Highlighting</h3>
<p>By default, the points greater than the default <code>genomewideline</code> and <code>effect_size_line</code> arguments are highlighted. The defaults are <code>genomewideline = -log10(1e-5)</code> and <code>effect_size_line = c(-1,1)</code>. The <code>effect_size_line</code> argument must be a numeric vector of length 2 and the first argument must be smaller than the second. To highlight more points, you simply need to change those thresholds. You can set either of the <code>genomewideline</code> and <code>effect_size_line</code> arguments to <code>FALSE</code> to remove that threshold:</p>

<pre>volcanoly(HapMap, snp = &quot;SNP&quot;,  genomewideline = -log10(1e-2), effect_size_line = FALSE)</pre>

<p><iframe height="800" width="900" src="http://plot.ly/~sahirbhatnagar/65.embed"></iframe></p>
<h3>Related Work</h3>
<p>The <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/manhattanly/">manhattanly</a> package is based on the <a target="_blank" rel="nofollow" href="https://github.com/stephenturner/qqman">qqman</a> package by <a target="_blank" rel="nofollow" href="http://stephenturner.us/">Stephen Turner</a>. It produces similar manhattan and Q-Q plots as the <code>qqman::manhattan</code> and <code>qqman::qq</code> functions; the main difference here is being able to interact with the plot, including extra annotation information, seamless integration with HTML and creating interactive volcano plots with automated highlighting of interesting points. </p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/interactive-volcano-plots-in-r-with-plotly/"></div></div><div><a data-url="https://www.r-bloggers.com/interactive-volcano-plots-in-r-with-plotly/" data-counturl="https://www.r-bloggers.com/interactive-volcano-plots-in-r-with-plotly/" data-count="vertical" data-text="Interactive Volcano Plots in R with Plotly" 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="http://moderndata.plot.ly/interactive-volcano-plots-r-plotly/"> R – Modern Data</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://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="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/cwCfyf0G8L0"></a></div>