<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/visualizing-reassortment-history-using-seqcombo/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://guangchuangyu.github.io/2017/12/visualizing-reassortment-history-using-seqcombo/"> R on Guangchuang YU</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Reassortment is an important strategy for influenza A viruses to<br>
introduce a HA subtype that is new to human populations, which creates<br>
the possibilities of pandemic.</p>
<p><img alt="" src="https://i0.wp.com/raw.githubusercontent.com/GuangchuangYu/seqcombo/master/vignettes/figures/srep25549-f2.jpg?w=456&ssl=1" data-recalc-dims="1"></p>
<p>A diagram showed above (Figure 2 of <code>doi:10.1038/srep25549</code>) is widely<br>
used to illustrate the reassortment events. While such diagrams are<br>
mostly manually draw and edit without software tool to automatically<br>
generate. Here, I implemented the <code>hybrid_plot</code> function for producing<br>
publication quality figure of reassortment events.</p>
<pre><code>library(tibble)
library(ggplot2)


n &lt;- 8

virus_info &lt;- tibble(
    id = 1:7,
    x = c(rep(1990, 4), rep(2000, 2), 2009),
    y = c(1,2,3,5, 1.5, 3, 4),
    segment_color = list(
        rep('purple', n),
        rep('red', n),
        rep('darkgreen', n),
        rep('lightgreen', n),
        c('darkgreen', 'darkgreen', 'red', 'darkgreen', 'red', 'purple', 'red', 'purple'),
        c('darkgreen', 'darkgreen', 'red', 'darkgreen', 'darkgreen', 'purple', 'red', 'purple'),
        c('darkgreen', 'lightgreen', 'lightgreen', 'darkgreen', 'darkgreen', 'purple', 'red', 'purple'))
)

flow_info &lt;- tibble(from = c(1,2,3,3,4,5,6),
                    to = c(5,5,5,6,7,6,7))
hybrid_plot(virus_info, flow_info)
</code></pre>
<p><img alt="" src="https://i0.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-2-1.png?w=456" data-recalc-dims="1"></p>

<p>The <code>hybrid_plot</code> requires two tibble data frame of virus information<br>
and genetic flow information.</p>
<p>Users need to provide <code>x</code> and <code>y</code> positions to plot the virus, this make<br>
sense for geographically and temporally information are usually<br>
available in such phylodynamic study and can be employed to set <code>x</code> or<br>
<code>y</code> to provide more information and help interpretation of the<br>
reassortment events.</p>
<p>We use hexagon to represent virus. Users can set the virus outer<br>
boundary color by <code>v_color</code> and fill the virus by <code>v_fill</code>. Color of<br>
line segments that indicate the genetic flow relationship can be specify<br>
via <code>l_color</code> parameter.</p>
<pre><code>hybrid_plot(virus_info, flow_info, v_color='firebrick', v_fill='darkgreen', l_color='steelblue')
</code></pre>
<p><img alt="" src="https://i0.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-3-1.png?w=456" data-recalc-dims="1"></p>
<p>We usually have more information to present, for example host<br>
information and HA subtype <em>etc.</em> and these information can be used to<br>
color the virus either by <code>v_color</code> or <code>v_fill</code></p>
<pre><code>virus_info$Host = c(&quot;Avian&quot;, &quot;Human&quot;, rep(&quot;Swine&quot;, 4), &quot;Human&quot;)
hybrid_plot(virus_info, flow_info, v_color=~Host, v_fill=~Host)
</code></pre>
<p><img alt="" src="https://i1.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-4-1.png?w=456" data-recalc-dims="1"></p>
<p>The relative virus size can also be specify if a <code>virus_size</code> column is<br>
available in the input <code>virus_info</code> data.</p>
<pre><code>virus_info$virus_size &lt;- c(rep(1, 3), 2, 1, 1, 1.5)
hybrid_plot(virus_info, flow_info, v_color=~Host, v_fill=~Host)
</code></pre>
<p><img alt="" src="https://i1.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-5-1.png?w=456" data-recalc-dims="1"></p>
<p>If <code>label</code> and <code>label_position</code> coloumns are available, the virus labels<br>
(virus name or other information) will be added automatically.</p>
<pre><code>virus_info$label &lt;- c(&quot;Avian&quot;, &quot;Human\nH3N2&quot;, &quot;Classic\nswine\nH1N1&quot;, &quot;Eurasian swine&quot;,
                      &quot;North American swine\n triple reassrotant H3N2&quot;,
                      &quot;North American swine\n triple reassortant H1N2&quot;, &quot;2009 Human H1N1&quot;)
virus_info$label_position &lt;- c('left', 'left', 'left', 'below', 'below', 'upper', 'below')
hybrid_plot(virus_info, flow_info, v_color=~Host, v_fill=~Host)
</code></pre>
<p><img alt="" src="https://i2.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-6-1.png?w=456" data-recalc-dims="1"></p>
<p>User can use <code>asp</code> to set the aspect ratio of hexagons, <code>asp &lt; 1</code> for<br>
thick/short and <code>asp > 1</code> for thin/tall.</p>
<pre><code>hybrid_plot(virus_info, flow_info, v_color=~Host, v_fill=~Host, asp=2)
</code></pre>
<p><img alt="" src="https://i1.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-7-1.png?w=456" data-recalc-dims="1"></p>
<p>The output of <code>hybrid_plot</code> is a <code>ggplot</code> object and users can use<br>
<code>ggplot2</code> to modify the details.</p>
<pre><code>title &lt;- &quot;Reassortment events in evolution of the 2009 influenza A (H1N1) virus&quot;
caption &lt;- 'Gene segments: PB2, PB1, PA, HA, NP, NA, M, NS'
color &lt;- c(Avian=&quot;purple&quot;, Human=&quot;red&quot;, Swine=&quot;darkgreen&quot;)

hybrid_plot(virus_info, flow_info, v_color=~Host, v_fill=~Host) +
    labs(caption=caption, title=title) +
    scale_color_manual(values=color) + scale_fill_manual(values=color) +
    scale_x_continuous(breaks=c(1990, 2000, 2009)) +
    xlab(NULL) + ylab(NULL) + theme_minimal() +
    theme(axis.line.y = element_blank(),
          axis.text.y = element_blank(),
          axis.ticks.y = element_blank(),
          panel.grid.minor=element_blank(),
          panel.grid.major.y=element_blank(),
          legend.position = c(.95, .1)
          )
</code></pre>
<p><img alt="" src="https://i2.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-8-1.png?w=456" data-recalc-dims="1"></p>
<p>Top-down or bottom-up style is also supported.</p>
<pre><code>x &lt;- virus_info$x
virus_info$x &lt;- virus_info$y
virus_info$y &lt;- x
virus_info$label_position &lt;- c(rep(&quot;right&quot;, 3), &quot;left&quot;, &quot;left&quot;, &quot;right&quot;, &quot;right&quot;)
hybrid_plot(virus_info, flow_info, v_color=~Host, v_fill=~Host) +
    scale_y_reverse() + scale_x_continuous(limits=c(0, 5.5))
</code></pre>
<p><img alt="" src="https://i2.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-9-1.png?w=456" data-recalc-dims="1"></p>
<p>User can also use Emoji to label the virus (host information in this<br>
example):</p>
<pre><code>virus_info$label &lt;- c(&quot;chicken&quot;, &quot;woman&quot;, &quot;pig&quot;, &quot;pig&quot;, &quot;pig&quot;, &quot;pig&quot;, &quot;woman&quot;)
hybrid_plot(virus_info, flow_info, v_color=~Host, v_fill=~Host,
              parse='emoji', t_size=8, t_color='firebrick') +
    scale_y_reverse()
</code></pre>
<p><img alt="" src="https://i1.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-10-1.png?w=456" data-recalc-dims="1"></p>
<p>In case you don’t have xy-coordination information, you can use<br>
<code>set_layout</code> function to auto setting the xy position using selected<br>
layout function.</p>
<pre><code>virus_info &lt;- set_layout(virus_info, flow_info, layout=&quot;layout.kamada.kawai&quot;)
hybrid_plot(virus_info, flow_info, parse='emoji', t_size=8, t_color='firebrick')
</code></pre>
<p><img alt="" src="https://i0.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-11-1.png?w=456" data-recalc-dims="1"></p>
<pre><code>virus_info &lt;- set_layout(virus_info, flow_info, layout=&quot;layout.fruchterman.reingold&quot;)
hybrid_plot(virus_info, flow_info, parse='emoji', t_size=8, t_color='firebrick')
</code></pre>
<p><img alt="" src="https://i2.wp.com/guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-11-2.png?w=456" data-recalc-dims="1"></p>
<hr>
<p>Please let me know if you know any published reassortment data that contain<br>
spatial information, I will demonstrate how to visualize reassortment<br>
history on a map.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://guangchuangyu.github.io/2017/12/visualizing-reassortment-history-using-seqcombo/"> R on Guangchuang YU</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 rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/bRflvaK7Q0Y" height="1"></a></div>