forked from GuangchuangYu/GuangchuangYu.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.xml
1150 lines (813 loc) · 81.8 KB
/
index.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Guangchuang YU on Guangchuang YU</title>
<link>https://guangchuangyu.github.io/</link>
<description>Recent content in Guangchuang YU on Guangchuang YU</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<copyright>&copy; 2016 Guangchuang YU</copyright>
<lastBuildDate>Wed, 20 Apr 2016 00:00:00 +0000</lastBuildDate>
<atom:link href="/" rel="self" type="application/rss+xml" />
<item>
<title>rename phylogeny tip labels in treeio</title>
<link>https://guangchuangyu.github.io/2018/04/rename-phylogeny-tip-labels-in-treeio/</link>
<pubDate>Thu, 19 Apr 2018 11:00:08 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2018/04/rename-phylogeny-tip-labels-in-treeio/</guid>
<description><p>I don’t know whether ‘rename taxa’ is a common task or not. It seems not a good idea to rename taxa in Newick tree text, since it may introduce problems when mapping the original sequence alignment to the tree.</p>
<p>If you just want to show different or additional information when plotting the tree, it is fine and easy to do it using <code>ggtree</code>:</p>
<!--more-->
<pre class="r"><code>require(treeio)</code></pre>
<pre><code>## Loading required package: treeio</code></pre>
<pre class="r"><code>require(ggtree)</code></pre>
<pre><code>## Loading required package: ggtree</code></pre>
<pre><code>## ggtree v1.13.1.9002 For help: https://guangchuangyu.github.io/software/ggtree
##
## If you use ggtree in published research, please cite:
## Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk Lam. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. Methods in Ecology and Evolution 2017, 8(1):28-36, doi:10.1111/2041-210X.12628</code></pre>
<pre class="r"><code>tr &lt;- read.tree(text = &quot;((a,(b,c)),d);&quot;)
genus &lt;- c(&quot;Gorilla&quot;, &quot;Pan&quot;, &quot;Homo&quot;, &quot;Pongo&quot;)
species &lt;- c(&quot;gorilla&quot;, &quot;spp.&quot;, &quot;sapiens&quot;, &quot;pygmaeus&quot;)
geo &lt;- c(&quot;Africa&quot;, &quot;Africa&quot;, &quot;World&quot;, &quot;Asia&quot;)
d &lt;- data.frame(label = tr$tip.label, genus = genus,
species = species, geo = geo)
d</code></pre>
<pre><code>## label genus species geo
## 1 a Gorilla gorilla Africa
## 2 b Pan spp. Africa
## 3 c Homo sapiens World
## 4 d Pongo pygmaeus Asia</code></pre>
<pre class="r"><code>ggtree(tr) %&lt;+% d + xlim(NA, 5) +
geom_tiplab(aes(label=paste0(&#39;italic(&#39;, genus, &#39;)~bolditalic(&#39;, species, &#39;)~&#39;, geo)), parse=T)</code></pre>
<p><img src="https://guangchuangyu.github.io/post/R/ggtree/treeio/rename_taxa_files/figure-html/unnamed-chunk-1-1.png" width="672" /></p>
<p>However, it is also possible to rename taxa of the tree object (either <code>treedata</code> or <code>phylo</code>) in <code>treeio</code>:</p>
<pre class="r"><code>tr2 = rename_taxa(tr, d, label, genus)
write.tree(tr2)</code></pre>
<pre><code>## [1] &quot;((Gorilla,(Pan,Homo)),Pongo);&quot;</code></pre>
<pre class="r"><code>d2 = dplyr::mutate(d, newlab = paste(genus, species, sep=&#39;|&#39;))
d2</code></pre>
<pre><code>## label genus species geo newlab
## 1 a Gorilla gorilla Africa Gorilla|gorilla
## 2 b Pan spp. Africa Pan|spp.
## 3 c Homo sapiens World Homo|sapiens
## 4 d Pongo pygmaeus Asia Pongo|pygmaeus</code></pre>
<pre class="r"><code>tr3 = rename_taxa(tr, d2, label, newlab)
write.tree(tr3)</code></pre>
<pre><code>## [1] &quot;((Gorilla|gorilla,(Pan|spp.,Homo|sapiens)),Pongo|pygmaeus);&quot;</code></pre>
<p>If the input tree object is a <code>treedata</code> instance, you can use <code>write.beast</code> to export the tree with associated data to a BEAST compatible NEXUS file.</p>
<div id="vignettes" class="section level2">
<h2>Vignettes</h2>
<ul>
<li><a href="http://bioconductor.org/packages/devel/bioc/vignettes/treeio/inst/doc/Importer.html">Importing trees with data</a></li>
<li><a href="http://bioconductor.org/packages/devel/bioc/vignettes/treeio/inst/doc/Exporter.html">Exporting trees with data</a></li>
</ul>
</div>
</description>
</item>
<item>
<title>setting ggplot2 background with ggbackground</title>
<link>https://guangchuangyu.github.io/2018/04/setting-ggplot2-background-with-ggbackground/</link>
<pubDate>Wed, 18 Apr 2018 21:00:00 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2018/04/setting-ggplot2-background-with-ggbackground/</guid>
<description><p><a href="https://cran.r-project.org/package=ggimage">ggimage</a> 0.1.4 is available on CRAN.</p>
<p>This release introduces a new function called <code>ggbackground</code> for setting image background as <code>ggplot</code> canvas.</p>
<pre class="r"><code>require(ggplot2)
p &lt;- ggplot(iris) + aes(x = Sepal.Length, y = Sepal.Width, color=Species) +
geom_point(size=5) + theme_classic()</code></pre>
<p>Suppose we have the above <code>ggplot</code> object, <code>p</code>, the only thing we need to do is passing the <code>p</code> with an image file name (local or remote) to <code>ggbackground</code>, as demonstrated below:</p>
<!--more-->
<pre class="r"><code>require(ggimage)
img = &quot;https://assets.bakker.com/ProductPics/560x676/10028-00-BAKI_20170109094316.jpg&quot;
ggbackground(p, img)</code></pre>
<p><img src="https://guangchuangyu.github.io/post/R/ggimage/ggbackground_files/figure-html/unnamed-chunk-3-1.png" width="672" /></p>
<p>This image file is too colorful and it is hard to see the patterns of the data points. We can manipulate the image using the functions provided by <code>magick</code> package. For example, the following function emulate a classic high-pass filter from photoshop:</p>
<pre class="r"><code>require(magick)
ggbackground(p, img,
image_fun = function(x) image_negate(image_convolve(x, &#39;DoG:0,0,2&#39;)))</code></pre>
<p><img src="https://guangchuangyu.github.io/post/R/ggimage/ggbackground_files/figure-html/unnamed-chunk-4-1.png" width="672" /></p>
<p>Here are examples of setting transparency and color:</p>
<pre class="r"><code>img = &quot;http://phylopic.org/assets/images/submissions/bf5fe2c5-1247-4ed9-93e2-d5af255ec462.512.png&quot;
p1 = ggbackground(p, img) + ggtitle(&quot;ggbackground(p, img)&quot;)
p2 = ggbackground(p, img, alpha=.3) + ggtitle(&quot;ggbackground(p, img, alpha=.3)&quot;)
p3 = ggbackground(p, img, alpha=.3, color=&quot;steelblue&quot;) + ggtitle(&#39;ggbackground(p, img, alpha=.3, color=&quot;steelblue&quot;)&#39;)
cowplot::plot_grid(p1, p2, p3, ncol=3)</code></pre>
<p><img src="https://guangchuangyu.github.io/post/R/ggimage/ggbackground_files/figure-html/unnamed-chunk-5-1.png" width="1152" /></p>
<div id="links" class="section level2">
<h2>Links</h2>
<ul>
<li>ggimage package: <a href="https://cran.r-project.org/package=ggimage">CRAN</a>, <a href="https://github.com/GuangchuangYu/ggimage">GitHub</a></li>
<li><a href="https://cran.r-project.org/web/packages/ggimage/vignettes/ggimage.html">ggimage introduction</a></li>
<li><a href="https://guangchuangyu.github.io/software/ggtree/vignettes/ggtree-ggimage.html">Annotating phylogenetic tree with images using ggtree and ggimage</a></li>
</ul>
</div>
</description>
</item>
<item>
<title>Annotating phylogenetic tree with images using ggtree and ggimage</title>
<link>https://guangchuangyu.github.io/2018/03/annotating-phylogenetic-tree-with-images-using-ggtree-and-ggimage/</link>
<pubDate>Thu, 01 Mar 2018 11:10:48 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2018/03/annotating-phylogenetic-tree-with-images-using-ggtree-and-ggimage/</guid>
<description><p>With <a href="https://cran.r-project.org/web/packages/ggimage/index.html">ggimage</a>, we are able to plot images using grammar of graphics. The layers defined in <a href="https://cran.r-project.org/web/packages/ggimage/index.html">ggimage</a> can be directly applied to <a href="https://guangchuangyu.github.io/ggtree">ggtree</a> to annotate phylogenetic tree using local/online image files.</p>
<p><a href="https://guangchuangyu.github.io/ggtree">ggtree</a> seamlessly work with <a href="https://cran.r-project.org/web/packages/ggimage/index.html">ggimage</a>. The <code>geom_tiplab</code> and <code>geom_nodelab</code> can accept parameter of <code>geom=&quot;image&quot;</code> to parse taxa labels as image files and use them to “label” the taxa using images instead of text strings. Here are some examples for demonstration.</p>
<!--more-->
<div id="annotate-tips" class="section level2">
<h2>Annotate tips</h2>
<pre class="r"><code>library(ggimage)
library(ggtree)
url &lt;- paste0(&quot;https://raw.githubusercontent.com/TreeViz/&quot;,
&quot;metastyle/master/design/viz_targets_exercise/&quot;)
x &lt;- read.tree(paste0(url, &quot;tree_boots.nwk&quot;))
info &lt;- read.csv(paste0(url, &quot;tip_data.csv&quot;))
p &lt;- ggtree(x) %&lt;+% info + xlim(NA, 6)
p + geom_tiplab(aes(image= imageURL), geom=&quot;image&quot;, offset=2, align=T, size=.16, hjust=0) +
geom_tiplab(geom=&quot;label&quot;, offset=1, hjust=.5)</code></pre>
<p><img src="https://guangchuangyu.github.io/post/R/ggtree/ggtree-ggimage_files/figure-html/unnamed-chunk-2-1.png" width="729.6" /></p>
</div>
<div id="annotate-internal-nodes" class="section level2">
<h2>Annotate internal nodes</h2>
<pre class="r"><code>## example from https://rgriff23.github.io/2017/05/11/primate-phylogeny-ggtree.html
library(ape)
tree &lt;- read.nexus(&quot;https://raw.githubusercontent.com/rgriff23/Dissertation/master/Chapter_2/data/tree.nex&quot;)
phylopic_info &lt;- data.frame(node = c(124, 113, 110, 96, 89, 70),
phylopic = c(&quot;7fb9bea8-e758-4986-afb2-95a2c3bf983d&quot;,
&quot;bac25f49-97a4-4aec-beb6-f542158ebd23&quot;,
&quot;f598fb39-facf-43ea-a576-1861304b2fe4&quot;,
&quot;aceb287d-84cf-46f1-868c-4797c4ac54a8&quot;,
&quot;0174801d-15a6-4668-bfe0-4c421fbe51e8&quot;,
&quot;72f2f854-f3cd-4666-887c-35d5c256ab0f&quot;),
species = c(&quot;galagoids&quot;, &quot;lemurs&quot;, &quot;tarsiers&quot;,
&quot;cebids&quot;, &quot;hominoids&quot;, &quot;cercopithecoids&quot;))
pg &lt;- ggtree(tree)
pg %&lt;+% phylopic_info + geom_nodelab(aes(image=phylopic), geom=&quot;phylopic&quot;, alpha=.5, color=&#39;steelblue&#39;)</code></pre>
<p><img src="https://guangchuangyu.github.io/post/R/ggtree/ggtree-ggimage_files/figure-html/unnamed-chunk-3-1.png" width="672" /></p>
<pre class="r"><code>d &lt;- data.frame(node = c(&quot;70&quot;,&quot;89&quot;,&quot;96&quot;,&quot;110&quot;,&quot;113&quot;,&quot;124&quot;),
images = c(&quot;https://i.imgur.com/8VA9cYw.png&quot;,
&quot;https://i.imgur.com/XYM1T2x.png&quot;,
&quot;https://i.imgur.com/EQs5ZZe.png&quot;,
&quot;https://i.imgur.com/2xin0UK.png&quot;,
&quot;https://i.imgur.com/hbftayl.png&quot;,
&quot;https://i.imgur.com/3wDHW8n.png&quot;))
pg %&lt;+% d + geom_nodelab(aes(image=images), geom=&quot;image&quot;)</code></pre>
<p><img src="https://guangchuangyu.github.io/post/R/ggtree/ggtree-ggimage_files/figure-html/unnamed-chunk-3-2.png" width="672" /></p>
</div>
<div id="use-image-as-background" class="section level2">
<h2>Use image as background</h2>
<pre class="r"><code>pg + geom_phylopic(image=&quot;79ad5f09-cf21-4c89-8e7d-0c82a00ce728&quot;, size=Inf, alpha=.5, color=&#39;firebrick&#39;)</code></pre>
<p><img src="https://guangchuangyu.github.io/post/R/ggtree/ggtree-ggimage_files/figure-html/unnamed-chunk-4-1.png" width="672" /></p>
<hr />
<p>Here is another example that uses <code>Tabikaeru</code> (known as traveling frog, a popular mobile game) image to decorate a phylogenetic tree of frog, see reproducible source code on <a href="https://github.com/GuangchuangYu/frog_tree" class="uri">https://github.com/GuangchuangYu/frog_tree</a>.</p>
<div class="figure">
<img src="https://raw.githubusercontent.com/GuangchuangYu/frog_tree/master/ggtree_frog.png" />
</div>
</div>
</description>
</item>
<item>
<title>visualizing reassortment history using seqcombo</title>
<link>https://guangchuangyu.github.io/2017/12/visualizing-reassortment-history-using-seqcombo/</link>
<pubDate>Tue, 05 Dec 2017 11:09:07 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2017/12/visualizing-reassortment-history-using-seqcombo/</guid>
<description><p>Reassortment is an important strategy for influenza A viruses to
introduce a HA subtype that is new to human populations, which creates
the possibilities of pandemic.</p>
<p><img src="https://raw.githubusercontent.com/GuangchuangYu/seqcombo/master/vignettes/figures/srep25549-f2.jpg" alt="" /></p>
<p>A diagram showed above (Figure 2 of <code>doi:10.1038/srep25549</code>) is widely
used to illustrate the reassortment events. While such diagrams are
mostly manually draw and edit without software tool to automatically
generate. Here, I implemented the <code>hybrid_plot</code> function for producing
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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-2-1.png" alt="" /></p>
<p></p>
<p>The <code>hybrid_plot</code> requires two tibble data frame of virus information
and genetic flow information.</p>
<p>Users need to provide <code>x</code> and <code>y</code> positions to plot the virus, this make
sense for geographically and temporally information are usually
available in such phylodynamic study and can be employed to set <code>x</code> or
<code>y</code> to provide more information and help interpretation of the
reassortment events.</p>
<p>We use hexagon to represent virus. Users can set the virus outer
boundary color by <code>v_color</code> and fill the virus by <code>v_fill</code>. Color of
line segments that indicate the genetic flow relationship can be specify
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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-3-1.png" alt="" /></p>
<p>We usually have more information to present, for example host
information and HA subtype <em>etc.</em> and these information can be used to
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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-4-1.png" alt="" /></p>
<p>The relative virus size can also be specify if a <code>virus_size</code> column is
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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-5-1.png" alt="" /></p>
<p>If <code>label</code> and <code>label_position</code> coloumns are available, the virus labels
(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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-6-1.png" alt="" /></p>
<p>User can use <code>asp</code> to set the aspect ratio of hexagons, <code>asp &lt; 1</code> for
thick/short and <code>asp &gt; 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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-7-1.png" alt="" /></p>
<p>The output of <code>hybrid_plot</code> is a <code>ggplot</code> object and users can use
<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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-8-1.png" alt="" /></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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-9-1.png" alt="" /></p>
<p>User can also use Emoji to label the virus (host information in this
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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-10-1.png" alt="" /></p>
<p>In case you don&rsquo;t have xy-coordination information, you can use
<code>set_layout</code> function to auto setting the xy position using selected
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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-11-1.png" alt="" /></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 src="http://guangchuangyu.github.io/blog_images/Bioconductor/seqcombo/reassortment_files/figure-markdown_strict/unnamed-chunk-11-2.png" alt="" /></p>
<hr />
<p>Please let me know if you know any published reassortment data that contain
spatial information, I will demonstrate how to visualize reassortment
history on a map.</p></description>
</item>
<item>
<title>BMC journal protects paper of plagiarism</title>
<link>https://guangchuangyu.github.io/2017/11/bmc-journal-protects-paper-of-plagiarism/</link>
<pubDate>Thu, 09 Nov 2017 21:51:43 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2017/11/bmc-journal-protects-paper-of-plagiarism/</guid>
<description><p>My friend who doing his PhD study at Johns Hopkins just send me the link about <a href="https://retractionwatch.com/2017/11/07/17-johns-hopkins-researchers-resign-protest-ed-board-nature-journal/" target="_blank">a SR paper of plagiarism</a>. I have very similar experence of <a href="https://bmcsystbiol.biomedcentral.com/articles/10.1186/1752-0509-7-S2-S8" target="_blank">a paper published on BMC Systems Biology</a>, which plagiarized <a href="https://www.ncbi.nlm.nih.gov/pubmed/20179076" target="_blank">my work</a> and the editor just decided to publish an erratum.</p>
<p>Deng <em>etc.</em> published an R package, ppiPre, that copied source code of my package, GOSemSim, and pretended that they developed these algorithms by themselves in their paper.</p>
<p>Here is the screenshot of the source code (left: ppiPre, right: GOSemSim).</p>
<p><img src="https://guangchuangyu.github.io/blog_images/screenshots/Screenshot 2017-07-17 19.43.51.png" alt="" /></p>
<p>You can find out more on <a href="http://guangchuangyu.github.io/2014/11/proper-use-of-gosemsim/" target="_blank">my blog post</a>.</p>
<p>As a developer of several open source software, I am glad that someone find my source code useful and happy if someone use my source code to make something better. But I am not happy if someone copies my source code by removing author information and changing function names to pretend the code was developed by himself. The situation is even worse in academic. Taking someone else&rsquo;s works and passing it off as one&rsquo;s own is definitely plagiarism and not allow in academic.</p>
<p></p>
<hr />
<p>After I found ppiPre plagiarized my work, I contacted the editor:</p>
<p><img src="http://guangchuangyu.github.io/blog_images/2015/plagiarism/Screenshot 2015-05-27 19.56.58.png" alt="" /></p>
<p>Very quickly, the editor replied my email:</p>
<p><img src="http://guangchuangyu.github.io/blog_images/2015/plagiarism/Screenshot%202015-05-27%2019.58.16.png" alt="" /></p>
<p>He told me that they &ldquo;do take cases of plagiarism very seriously&rdquo;. I don&rsquo;t know how long their &ldquo;due course&rdquo; is and waited for the editor&rsquo;s reply for 5 months without receiving any updated information. I then contacted CRAN for the issue of the ppiPre that copied source code without acknowledgement and the package was removed from CRAN at that time. After that I sent another email to the editor to ask for update.</p>
<p>Here is the reply:</p>
<p><img src="http://guangchuangyu.github.io/blog_images/2015/plagiarism/Screenshot%202015-05-27%2020.11.54.png" alt="" /></p>
<p>In the passed 5 months, they never even contacted the authors.</p>
<p>I waited for 2 more months and also didn&rsquo;t receive any information. I sent them email to complain that they are ruining the reputation of their journal.</p>
<p>At this time, the editor told me he had contacted the author and we can &ldquo;expect an update soon&rdquo;.</p>
<p><img src="http://guangchuangyu.github.io/blog_images/2015/plagiarism/Screenshot%202015-05-27%2020.33.30.png" alt="" /></p>
<p>I waited for another 3 months and as usual without any update received. I sent another email to ask for update.</p>
<p>Here is the reply of the editor:</p>
<p><img src="http://guangchuangyu.github.io/blog_images/2015/plagiarism/Screenshot%202015-04-23%2021.31.55.png" alt="" /></p>
<p>The author said that they just &ldquo;failing to cite my work&rdquo;. Of course this is not an issue of citation as they pretended that they implemented several algorithms that were actually developed by me in their paper. This is definitely plagiarism. The editor&rsquo;s words, &ldquo;submit a correction&rdquo; and &ldquo;within our policy&rdquo;, indicate that the editor is totally fine for a paper of plagiarism to say sorry and publish a correction. (BTW: this is the last email I received from the editor)</p>
<p>Of course I can&rsquo;t accept this, and here is my repsponse:</p>
<p><img src="http://guangchuangyu.github.io/blog_images/2015/plagiarism/Screenshot%202015-04-23%2021.45.33.png" alt="" /></p>
<blockquote>
<p>Ignorance of the law is no defence, for otherwise anyone can choose not to know the law and have a defence in committing an offence. The same applies to plagiarism.</p>
</blockquote>
<p>Ignorance of GPL license is also not an defence of publishing someone else&rsquo;s work in a scientific journal to claim that they did it themselves.</p>
<p>AND AGAIN, the editor just disappear. I sent emails several times to several editors and they just ignore my emails.</p>
<p>I wrote <a href="https://guangchuangyu.github.io/2015/05/bmc-favors-source-code-plagiarism/" target="_blank">blog post</a> and asked peoples to share it on twitter and weibo. Then the first author contacted me. After <a href="https://guangchuangyu.github.io/cn/2017/07/un-fucking-believable/" target="_blank">severl emails&rsquo; communication</a>, he promised to retract his paper and even send me a statement:</p>
<p><img src="https://guangchuangyu.github.io/blog_images/Bioconductor/GOSemSim/2017-07-20-002402_683x584_scrot.png" alt="" /></p>
<p>I never know how they interact with the editors. It was totally a black box for me as I never receive any email from both sides after the email above. They did not keep me updated. Even after they decided to publish an erratum, they didn&rsquo;t notify me of their decision.</p>
<hr />
<p>Here is their <a href="https://bmcsystbiol.biomedcentral.com/articles/10.1186/s12918-015-0196-5" target="_blank">erratum</a>:</p>
<blockquote>
<p>The authors wish to acknowledge that the software package associated with our Research Article [1], under the name ‘ppiPre’, re-used software code for some of its functions from an existing software package, GOSemSim [2], without proper attribution and in breach of the software’s licencing terms. Additionally we neglected to cite the article by Yu et al. [3] describing the GoSemSim software.</p>
<p>The software code from GoSemSim [2] is used in the implementation of two GO semantic similarity measures, TCSS and IntelliGO. ppiPre additionally implements a KEGG-based similarity measure and three topological similarity measures, and integrates features with a support vector machine.</p>
<p>We have now updated our software package such that it is licensed under a compatible GPL version 2 licence, and revised the package to give the appropriate attribution.</p>
<p>We apologize for any inconvenience this oversight may have caused.</p>
</blockquote>
<p>They just <strong>&ldquo;re-used&rdquo;</strong> source code <strong>&ldquo;without proper attribution&rdquo;</strong> and these source code &ldquo;<strong>is used in the implementation</strong> of two GO semantic similarity measures&rdquo;. It seems that they implemented these methods themselves. Of course the paper is not only an issue of source code plagiarism, but also an issue of publication ethics. The ppiPre paper intended to introduce my implementation of GO semantic similarity measurement as their own to cheat reviewers and readers. They did not say a word about publication ethics and the editors also ignore such issue.</p>
<p>The case is very clear that they copied my source code and intended to pretend that&rsquo;s their original work and use it to publish a paper. That&rsquo;s definitely plagiarism. I am very disappointed! The editors are protecting paper of plagiarism and encouraging people to steal other&rsquo;s work and publish on BMC.</p></description>
</item>
<item>
<title>shadow text effect in grid and ggplot2 graphics</title>
<link>https://guangchuangyu.github.io/2017/11/shadow-text-effect-in-grid-and-ggplot2-graphics/</link>
<pubDate>Thu, 02 Nov 2017 15:30:00 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2017/11/shadow-text-effect-in-grid-and-ggplot2-graphics/</guid>
<description><p>After the release of <code>meme</code> package, I received several feedbacks from users.</p>
<p>The most usefule one is <a href="http://disq.us/p/1n9zi69" target="_blank">the comment</a> on my blog post:</p>
<blockquote>
<p>Sercan Kahveci</p>
<p>Greetings Mr. Yu,</p>
<p>I am very happy that this package exists. Thank you for making it! I would like to request a feature, to ensure the package is able to compete with professional meme-creation tools like memegenerator and paint.net. Since memes often use the font Impact, in white and with black outline, I believe the package would be more powerful if it also did that automatically.</p>
<p>Regards,</p>
<p>Sercan Kahveci, MSc</p>
<p>Content creator at Questionable Research Memes on Facebook
<a href="https://www.facebook.com/QResearchMemes/" target="_blank">https://www.facebook.com/QResearchMemes/</a></p>
</blockquote>
<p>The words, &lsquo;compete with professional meme-creation tools&rsquo;, stimulated me to develop text plotting with background outline effect.</p>
<p>Now this feature is available in <a href="https://cran.r-project.org/package=meme" target="_blank">meme</a> v&gt;=0.0.7, which can be downloaded from CRAN.</p>
<p></p>
<p>Here is an example:</p>
<pre><code>library(meme)
u &lt;- system.file(&quot;angry8.jpg&quot;, package=&quot;meme&quot;)
meme(u, &quot;code&quot;, &quot;all the things!&quot;)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/shadowtext.png" alt="" /></p>
<hr />
<p>To make this <strong>shadow text</strong> feature available to the R community, I created another package, <a href="https://cran.r-project.org/web/packages/shadowtext/" target="_blank">shadowtext</a>, that creates/draws text grob with background shadow for <code>grid</code> and <code>ggplot2</code>. If you are interesting, please refer to the <a href="https://cran.r-project.org/web/packages/shadowtext/vignettes/shadowtext.html" target="_blank">online vignette</a>.</p>
<p><img src="https://guangchuangyu.github.io/blog_images/R/shadowtext/shadowtext_files/figure-markdown_strict/unnamed-chunk-2-1.png" alt="" /></p>
<p><img src="https://guangchuangyu.github.io/blog_images/R/shadowtext/shadowtext_files/figure-markdown_strict/unnamed-chunk-3-2.png" alt="" /></p></description>
</item>
<item>
<title>create meme in R</title>
<link>https://guangchuangyu.github.io/2017/10/create-meme-in-r/</link>
<pubDate>Wed, 25 Oct 2017 15:13:35 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2017/10/create-meme-in-r/</guid>
<description><p>I developed a tiny toy package, <code>meme</code>, which is now on CRAN. As it&rsquo;s name indicated, it was designed to create memes, which are captioned photos that are intended to be funny, riduculous.</p>
<h2 id="meme"><code>meme()</code></h2>
<p>The package is quite simple. You can use <code>meme()</code> function to add meme captions, and this is all the package supposed to do:</p>
<pre><code class="language-r">library(meme)
u &lt;- &quot;http://www.happyfamilyneeds.com/wp-content/uploads/2017/08/angry8.jpg&quot;
meme(u, &quot;code&quot;, &quot;all the things!&quot;)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/Figs/unnamed-chunk-2-1.png" alt="" /></p>
<p></p>
<h2 id="the-grammar">the grammar 🙈</h2>
<p>The <code>meme</code> package was implemented using <code>grid</code> graphic system. Since <code>grid</code> is the most flexible graphic system in R, I try to mimic <code>ggplot2</code> (although very superficial) for practice.</p>
<p>User can use <code>mmplot()</code> to read and plot the input image and then using <code>+ mm_caption()</code> to add meme captions.</p>
<pre><code class="language-r">mmplot(u) + mm_caption(&quot;calm down&quot;, &quot;and RTFM&quot;, color=&quot;purple&quot;)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/Figs/unnamed-chunk-3-1.png" alt="" /></p>
<h2 id="meme-save"><code>meme_save()</code></h2>
<p>The <code>meme</code> output can be saved as an object, and can be exported to file using <code>ggsave()</code>. Since we would like to keep the original figure aspect ratio for output meme figure, I provide a helper function, <code>meme_save()</code>, which takes care of the figure aspect ratio and then called <code>ggsave()</code> to export the figure.</p>
<pre><code class="language-r">u2 &lt;- &quot;http://i0.kym-cdn.com/entries/icons/mobile/000/000/745/success.jpg&quot;
x &lt;- meme(u2, &quot;please&quot;, &quot;tell me more&quot;)
meme_save(x, file=&quot;docs/Figs/meme.png&quot;)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/Figs/meme.png" width="672"/></p>
<h2 id="the-plot-method">the <code>plot</code> method</h2>
<p>Users can <code>plot</code> the <code>meme()</code> output and change the caption or other parameters in real time.</p>
<pre><code class="language-r">plot(x, size = 2, &quot;happy friday!&quot;, &quot;wait, sorry, it's monday&quot;, color = &quot;firebrick&quot;, font = &quot;Courier&quot;)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/Figs/unnamed-chunk-5-1.png" alt="" /></p>
<h2 id="the-method">the <code>+</code> method</h2>
<p>Instead of using parameters in <code>plot()</code> explictely, Users can use <code>+ aes()</code> to set the plot parameters:</p>
<pre><code class="language-r">x + aes(upper = &quot;#barbarplots&quot;,
lower = &quot;friends don't let friends make bar plots&quot;,
color = firebrick, font = Courier, size=1.5)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/Figs/unnamed-chunk-6-1.png" alt="" /></p>
<p>or using <code>+ list()</code>. The following command will also generate the figure displayed above.</p>
<pre><code class="language-r">x + list(upper = &quot;#barbarplots&quot;,
lower = &quot;friends don't let friends make bar plots&quot;,
color = &quot;firebrick&quot;, font = &quot;Courier&quot;, size=1.5)
</code></pre>
<h2 id="multi-language-support">multi-language support</h2>
<p>I didn&rsquo;t do anything about it. Multi-language was supported internally. Just simply select a font for your language.</p>
<pre><code class="language-r">y &lt;- meme(u, &quot;卧槽&quot;, &quot;听说你想用中文&quot;, font=&quot;STHeiti&quot;)
y
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/Figs/unnamed-chunk-8-1.png" alt="" /></p>
<hr />
<p>As the <code>meme</code> package was developed using <code>grid</code>, It would be better to provide function to convert the output object to <code>grob</code>. Similar to <code>ggplotGrob()</code> for <code>ggplot</code> object, I provide <code>memeGrob()</code> for the <code>meme</code> object and this making it possible to edit the details of the graph and compatible with the <code>grid</code> ecosystem.</p>
<p>Here are the examples of using <code>meme</code> in <code>grid</code>, <code>ggplot2</code> and <code>cowplot</code>.</p>
<h2 id="grid-support">grid support</h2>
<pre><code class="language-r">library(grid)
mm &lt;- meme(u, &quot;code&quot;, &quot;all the things!&quot;, size=.3, color='firebrick')
grid.newpage()
pushViewport(viewport(width=.9, height=.9))
grid.rect(gp = gpar(lty=&quot;dashed&quot;))
xx &lt;- seq(0, 2*pi , length.out=10)
yy &lt;- sin(xx)
for (i in seq_along(xx)) {
vp &lt;- viewport(x = xx[i]/(2*pi), y = (yy[i]-min(yy))/2, width=.05, height=.05)
print(mm, vp = vp)
}
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/Figs/unnamed-chunk-9-1.png" alt="" /></p>
<h2 id="ggplot2-support">ggplot2 support</h2>
<pre><code class="language-r">library(ggplot2)
library(ggimage)
d &lt;- data.frame(x = xx, y = yy)
ggplot(d, aes(x, y)) + geom_line() +
geom_subview(mm, x = xx, y = yy, width=.3, height=.15)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/Figs/unnamed-chunk-10-1.png" alt="" /></p>
<pre><code class="language-r">ggplot(d, aes(x, y)) +
geom_subview(mm+aes(size=3), x=0, y=0, width=Inf, height=Inf) +
geom_point() + geom_line()
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/Figs/unnamed-chunk-10-2.png" alt="" /></p>
<h2 id="cowplot-support">cowplot support</h2>
<pre><code class="language-r">cowplot::plot_grid(x, y, ncol=1, labels = c(&quot;A&quot;, &quot;B&quot;))
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/meme/Figs/unnamed-chunk-11-1.png" alt="" /></p></description>
</item>
<item>
<title>joyplot for GSEA result</title>
<link>https://guangchuangyu.github.io/2017/08/joyplot-for-gsea-result/</link>
<pubDate>Sun, 20 Aug 2017 20:51:00 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2017/08/joyplot-for-gsea-result/</guid>
<description><p>I am very glad to find that someone figure out <a href="https://stackoverflow.com/questions/45384281/ggjoy-facet-with-ggtree" target="_blank">how to use ggjoy with ggtree</a>.</p>
<p><img src="https://i.stack.imgur.com/U7D3j.png" alt="" /></p>
<p>I really love ggjoy and believe it can be a good tool to visualize gene set enrichment (GSEA) result. DOSE/clusterProfiler support several visualization methods.</p>
<p></p>
<p><strong>running score:</strong></p>
<p><img src="https://guangchuangyu.github.io/blog_images/Bioconductor/clusterProfiler/mesh_gsea.png" alt="" /></p>
<p><strong>enrichment map:</strong></p>
<p><img src="https://guangchuangyu.github.io/blog_images/Bioconductor/ReactomePA/c5mb00663e-f1_hi-res.gif" alt="" /></p>
<p><strong>category-gene-network:</strong></p>
<p><img src="https://guangchuangyu.github.io/blog_images/Bioconductor/clusterProfiler/2016_GO_analysis_using_clusterProfiler_files/figure-markdown_strict/unnamed-chunk-4-3.png" alt="" /></p>
<p><strong>dotplot:</strong></p>
<p><img src="https://guangchuangyu.github.io/blog_images/Bioconductor/DOSE/dotplot_geneRatio.png" alt="" /></p>
<hr />
<p>These visualization methods are designed for visualizing/summarizing enrichment results and none of them can incoporate expression values.</p>
<p>In DOSE v&gt;=3.3.2, I defined a <code>joyplot</code> function, which can visualize GSEA result with expression distribution of the enriched categories.</p>
<p>Here is an example:</p>
<pre><code class="language-r">require(clusterProfiler)
data(geneList)
x &lt;- gseKEGG(geneList)
joyplot(x)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/Bioconductor/DOSE/joyplot_gsea.png" alt="" /></p></description>
</item>
<item>
<title>pixel art of ggplot2 faceting using geofacet</title>
<link>https://guangchuangyu.github.io/2017/06/pixel-art-of-ggplot2-faceting-using-geofacet/</link>
<pubDate>Mon, 26 Jun 2017 20:13:35 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2017/06/pixel-art-of-ggplot2-faceting-using-geofacet/</guid>
<description><p>I just discovered an interesting <code>ggplot2</code> extension, <code>geofacet</code>, that supports arranging facet panels that mimics geographic topoloty.</p>
<p>After playing with it, I realized that it is not only for visualizing <code>geo</code>-related data, but also can be fun for presenting data to mimics pixel art.</p>
<p><img src="https://guangchuangyu.github.io/blog_images/2017/Screenshot 2017-06-26 15.49.50.png" alt="" /></p>
<p></p>
<p>Here is an example using the Turkey shape:</p>
<pre><code class="language-r">Turkey &lt;- read.csv(&quot;http://pages.iu.edu/~cdesante/turkey.csv&quot;)
colnames(Turkey)[2:1] = c(&quot;row&quot;, &quot;col&quot;)
Turkey$row = max(Turkey$row) - Turkey$row +1
Turkey$name &lt;- Turkey$code &lt;- paste0('turkey', 1:nrow(Turkey))
require(ggplot2)
require(geofacet)
x &lt;- split(eu_gdp, eu_gdp$code)
x &lt;- x[sample.int(length(x), nrow(Turkey), replace=T)]
for (i in 1:length(x)) {
x[[i]]$code = Turkey$code[i]
}
y &lt;- do.call(rbind, x)
color = Turkey$Turkey.Colors
names(color) = Turkey$code
y$color = color[y$code]
Turkey = Turkey[, -3]
p1 &lt;- ggplot(y, aes(gdp_pc, year))+ geom_line() +
facet_geo(~code, grid=Turkey, scales='free')
print(p1)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/geofacet/Screenshot 2017-06-26 14.00.53.png" alt="" /></p>
<pre><code class="language-r">p1 + theme_void() + aes(color=color) + theme(strip.text.x = element_blank(), legend.position='none')
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/geofacet/Screenshot 2017-06-26 19.44.30.png" alt="" /></p></description>
</item>
<item>
<title>[Bioc 3.5] NEWS of my BioC packages</title>
<link>https://guangchuangyu.github.io/2017/05/bioc-3.5-news-of-my-bioc-packages/</link>
<pubDate>Fri, 19 May 2017 18:13:57 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2017/05/bioc-3.5-news-of-my-bioc-packages/</guid>
<description><p>I have 8 packages published within the <code>Bioconductor</code> project.</p>
<ul>
<li><a href="http://guangchuangyu.github.io/ChIPseeker" target="_blank">ChIPseeker</a></li>
<li><a href="http://guangchuangyu.github.io/clusterProfiler" target="_blank">clusterProfiler</a></li>
<li><a href="http://guangchuangyu.github.io/DOSE" target="_blank">DOSE</a></li>
<li><a href="http://guangchuangyu.github.io/ggtree" target="_blank">ggtree</a></li>
<li><a href="http://guangchuangyu.github.io/GOSemSim" target="_blank">GOSemSim</a></li>
<li><a href="http://guangchuangyu.github.io/meshes" target="_blank">meshes</a></li>
<li><a href="http://guangchuangyu.github.io/ReactomePA" target="_blank">ReactomePA</a></li>
<li><a href="http://guangchuangyu.github.io/treeio" target="_blank">treeio</a></li>
</ul>
<p>A new package <a href="http://guangchuangyu.github.io/treeio" target="_blank">treeio</a> was included in BioC 3.5 release.</p>
<p></p>
<h2 id="chipseeker">ChIPseeker</h2>
<p>Bug fixed of <a href="https://github.com/GuangchuangYu/ChIPseeker/issues/54" target="_blank">intron rank</a> and optimized <code>getGeneAnno</code> function.</p>
<h2 id="clusterprofiler">clusterProfiler</h2>
<ol>
<li>Defined <code>simplify</code> generics as it was removed from IRanges.</li>
<li><code>enrichGO</code> now supports <code>ont=&quot;ALL&quot;</code> and will test three GO ontologies simultaneously.</li>
<li><code>dotplot</code> for <code>compareClusterResult</code> not supports three GO sub-ontologies.</li>
<li><code>bitr_kegg</code> supports converting Path/Module to geneID and vice versa.</li>
<li><code>plotGOgraph</code> supports <code>gseGO</code> output by using core enriched gene.</li>
<li>see the updates of <code>DOSE</code> for other updates.</li>
</ol>
<h2 id="dose">DOSE</h2>
<ul>
<li>Now user can use <code>options(mc.cores=x)</code> to specify x cores for GSEA analysis.</li>
<li>throw more friendly error msg if <code>setReadable</code> function fail to determine <code>setType</code> automatically.</li>
<li>Call <code>grid.newpage</code> in <code>gseaplot</code> only if <code>dev.interactive()</code> is TRUE.</li>
<li><a href="http://guangchuangyu.github.io/2016/12/dotplot-for-gsea-result/" target="_blank"><code>dotplot</code> now supports <code>gseaResult</code></a>.</li>
<li>Output expected sample gene ID (sample from background) when input gene ID type not match.</li>
</ul>
<h2 id="ggtree">ggtree</h2>
<p>Now <code>ggtree</code> was splitted to <code>treeio</code> for tree input and output, and <code>ggtree</code> for tree visualization and annotation.</p>
<ul>
<li><code>facet_plot</code> supports <code>ggbio::geom_alignment</code>.</li>
<li><a href="https://guangchuangyu.github.io/2016/10/xlim_tree-set-x-axis-limits-for-only-tree-panel/" target="_blank">support setting x axis limits of Tree panel via <code>xlim_tree</code></a>.</li>
<li><a href="https://guangchuangyu.github.io/2016/10/xlim_tree-set-x-axis-limits-for-only-tree-panel/" target="_blank"><code>xlim_expand</code> for setting x axis limits of any specific panel</a>.</li>
<li><code>revts</code> for <a href="https://github.com/GuangchuangYu/ggtree/issues/87" target="_blank">reverse time scale</a>.</li>
<li><a href="https://groups.google.com/forum/#!topic/bioc-ggtree/Q4LnwoTf1DM" target="_blank"><code>groupOTU</code> method now accept &lsquo;overlap = c(&ldquo;overwrite&rdquo;, &ldquo;origin&rdquo;, &ldquo;abandon&rdquo;)&rsquo; parameter</a></li>
<li><a href="https://github.com/GuangchuangYu/ggtree/issues/98" target="_blank">2-dimensional tree layout supports <code>phylo4d</code> object</a></li>
<li><code>aes(subset)</code> now support logical vector contains NA</li>
<li><a href="https://cran.r-project.org/web/packages/emojifont/vignettes/phylomoji.html" target="_blank">supports parse=&ldquo;emoji&rdquo; in geom_cladelabel, geom_text2, geom_label2, geom_tiplab, geom_tiplab2</a></li>
<li>unrooted layout now supports &lsquo;daylight&rsquo; algorithm</li>
</ul>
<h2 id="gosemsim">GOSemSim</h2>
<p>only documentation update.</p>
<h2 id="meshes">meshes</h2>
<p>no update</p>
<h2 id="reactomepa">ReactomePA</h2>
<p>only documentation update.</p>
<h2 id="treeio">treeio</h2>
<ul>
<li>defined new tree class <code>treedata</code>.</li>
<li><a href="http://guangchuangyu.github.io/2017/01/convert-graphic-object-to-tree-object-using-treeio/" target="_blank"><code>as.treeedata.ggtree</code> can convert <code>ggtree</code> output to <code>treedata</code> object</a>.</li>
<li><a href="http://guangchuangyu.github.io/2017/01/convert-graphic-object-to-tree-object-using-treeio/" target="_blank"><code>as.phylo.ggtree</code> can convert <code>ggtree</code> output to <code>phylo</code> object</a>.</li>
<li><code>as.treedata.phylo4</code> &amp; as.treedata.phylo4d for converting <code>phylo4</code> and <code>phylo4d</code> object to <code>treedata</code> object.</li>
<li><code>read.beast</code> now also supports MrBayes output</li>
<li><code>read.newick</code> for parsing <code>node.label</code> as support values.</li>
<li><code>drop.tip</code> method for `treedata object.
<br /></li>
</ul>
<h2 id="citation">Citation</h2>
<p><strong><em>Yu G</em></strong>, Wang LG and He QY<sup>*</sup>. <a href="http://bioinformatics.oxfordjournals.org/content/31/14/2382" target="_blank">ChIPseeker: an R/Bioconductor package for ChIP peak annotation, comparison and visualization</a>. <strong><em>Bioinformatics</em></strong> 2015, 31(14):2382-2383.</p>
<p><script type="text/javascript" src="https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js"></script><div class="altmetric-embed" data-badge-type="donut" data-badge-popover="right" data-altmetric-id="3781087"></div></p>
<p><strong><em>Yu G</em></strong>, Wang L, Han Y and He Q<sup>*</sup>. <a href="http://online.liebertpub.com/doi/abs/10.1089/omi.2011.0118" target="_blank">clusterProfiler: an R package for comparing biological themes among gene clusters</a>. <strong><em>OMICS: A Journal of Integrative Biology</em></strong>. 2012, 16(5):284-287.</p>
<p><script type="text/javascript" src="https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js"></script><div class="altmetric-embed" data-badge-type="donut" data-badge-popover="right" data-altmetric-id="681089"></div></p>
<p><strong><em>G Yu</em></strong>, LG Wang, GR Yan, QY He. <a href="http://bioinformatics.oxfordjournals.org/content/31/4/608" target="_blank">DOSE: an R/Bioconductor package for Disease Ontology Semantic and Enrichment analysis</a>. <strong><em>Bioinformatics</em></strong> 2015, 31(4):608-609.</p>
<p><script type="text/javascript" src="https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js"></script><div class="altmetric-embed" data-badge-popover="right" data-badge-type="donut" data-altmetric-id="2788597"></div></p>
<p><strong>G Yu</strong>, DK Smith, H Zhu, Y Guan, TTY Lam<sup>*</sup>. <a href="http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12628/abstract" target="_blank">ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data</a>. <strong><em>Methods in Ecology and Evolution</em></strong>. <a href="http://dx.doi.org/10.1111/2041-210X.12628" target="_blank"><code>doi:10.1111/2041-210X.12628</code></a>.</p>
<p><script type="text/javascript" src="https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js"></script>
<div data-badge-popover="right" data-badge-type="donut" data-doi="10.1111/2041-210X.12628" class="altmetric-embed"></div></p>
<p><strong>Yu G</strong><sup>†</sup>, Li F<sup>†</sup>, Qin Y, Bo X<sup>*</sup>, Wu Y and Wang S<sup>*</sup>. <a href="http://bioinformatics.oxfordjournals.org/content/26/7/976" target="_blank">GOSemSim: an R package for measuring semantic similarity among GO terms and gene products</a>. <strong><em>Bioinformatics</em></strong>. 2010, 26(7):976-978.</p>
<p><script type="text/javascript" src="https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js"></script>
<div class="altmetric-embed" data-badge-popover="right" data-badge-type="donut" data-altmetric-id="100979"></div></p>
<p><strong><em>G Yu</em></strong>, QY He<sup>*</sup>. <a href="http://pubs.rsc.org/en/Content/ArticleLanding/2016/MB/C5MB00663E#!divAbstract" target="_blank">ReactomePA: an R/Bioconductor package for reactome pathway analysis and visualization</a>. <strong><em>Molecular BioSystems</em></strong> 2016, 12(2):477-479.</p>
<p><script type="text/javascript" src="https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js"></script><div class="altmetric-embed" data-badge-popover="right" data-badge-type="donut" data-altmetric-id="4796667"></div></p></description>
</item>
<item>
<title>Phylomoji with ggtree and emojifont</title>
<link>https://guangchuangyu.github.io/2017/05/phylomoji-with-ggtree-and-emojifont/</link>
<pubDate>Wed, 17 May 2017 11:11:11 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2017/05/phylomoji-with-ggtree-and-emojifont/</guid>
<description><p>With ggtree (Yu et al. 2017), it is very easy to create phylomoji. Emoji is internally supported by ggtree.</p>
<h2 id="use-emoji-in-taxa-labels">Use emoji in taxa labels</h2>
<pre><code class="language-r">library(ggtree)
tree_text &lt;- &quot;(((((cow, (whale, dolphin)), (pig2, boar)), camel), fish), seedling);&quot;
x &lt;- read.tree(text=tree_text)
ggtree(x, linetype=&quot;dashed&quot;, color='firebrick') +
xlim(NA, 7) + ylim(NA, 8.5) +
geom_tiplab(aes(color=label), parse='emoji', size=14, vjust=0.25) +
labs(title=&quot;phylomoji&quot;, caption=&quot;powered by ggtree + emojifont&quot;)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/emojifont/phylomoji_files/figure-markdown_github/unnamed-chunk-2-1.png" alt="" /></p>
<p></p>
<pre><code class="language-r">p &lt;- ggtree(x, layout='circular') +
geom_tiplab2(aes(color=label), parse='emoji', size=12, vjust=0.25)
print(p)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/emojifont/phylomoji_files/figure-markdown_github/unnamed-chunk-3-1.png" alt="" /></p>
<pre><code class="language-r">open_tree(p, angle=200)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/emojifont/phylomoji_files/figure-markdown_github/unnamed-chunk-4-1.png" alt="" /></p>
<pre><code class="language-r">open_tree(p, angle=60) %&gt;% rotate_tree(-75)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/emojifont/phylomoji_files/figure-markdown_github/unnamed-chunk-4-2.png" alt="" /></p>
<h2 id="labeling-clades-using-emoji">Labeling clades using emoji</h2>
<pre><code class="language-r">set.seed(123)
tr &lt;- rtree(30)
ggtree(tr) + xlim(NA, 5) +
geom_cladelabel(node=41, label=&quot;chicken&quot;, parse=&quot;emoji&quot;,
fontsize=12, align=TRUE, color=&quot;firebrick&quot;) +
geom_cladelabel(node=51, label=&quot;duck&quot;, parse=&quot;emoji&quot;,
fontsize=12, align=TRUE, color=&quot;steelblue&quot;) +
geom_cladelabel(node=32, label=&quot;family&quot;, parse=&quot;emoji&quot;,
fontsize=12, align=TRUE, color=&quot;darkkhaki&quot;)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/emojifont/phylomoji_files/figure-markdown_github/unnamed-chunk-5-1.png" alt="" /></p>
<h2 id="apple-color-emoji">Apple Color Emoji</h2>
<p>Although <code>R</code>&rsquo;s graphical devices don&rsquo;t support <code>AppleColorEmoji</code> font, it&rsquo;s still possible to use it. We can export the <code>plot</code> to <code>svg</code> file and render it in <code>Safari</code>.</p>
<pre><code class="language-r">library(ggimage)
library(gridSVG)
p &lt;- ggtree(x, size=2) + geom_tiplab(size=20, parse='emoji') +
xlim(NA, 7) + ylim(NA, 8.5) +
geom_phylopic(image=&quot;79ad5f09-cf21-4c89-8e7d-0c82a00ce728&quot;,
color=&quot;firebrick&quot;, alpha = .3, size=Inf)
p
ps = grid.export(&quot;emoji.svg&quot;, addClass=T)
</code></pre>
<p><img src="https://guangchuangyu.github.io/blog_images/R/emojifont/apple_emoji2.png" alt="" /></p>
<h2 id="further-reading">Further reading</h2>
<p>Please visit ggtree homepage, <a href="https://guangchuangyu.github.io/ggtree" target="_blank">https://guangchuangyu.github.io/ggtree</a>, to find out more.</p>
<h1 id="references">References</h1>
<p>Yu, Guangchuang, David Smith, Huachen Zhu, Yi Guan, and Tommy Tsan-Yuk Lam. 2017. “Ggtree: An R Package for Visualization and Annotation of Phylogenetic Trees with Their Covariates and Other Associated Data.” <em>Methods in Ecology and Evolution</em> 8 (1): 28–36. doi:<a href="https://doi.org/10.1111/2041-210X.12628" target="_blank">10.<sup>1111</sup>&frasl;<sub>2041</sub>-210X.12628</a>.</p>
<p><script type="text/javascript" src="https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js"></script>
<div data-badge-popover="right" data-badge-type="donut" data-doi="10.1111/2041-210X.12628" class="altmetric-embed"></div></p></description>
</item>
<item>
<title>convert graphic object to tree object using treeio</title>
<link>https://guangchuangyu.github.io/2017/01/convert-graphic-object-to-tree-object-using-treeio/</link>
<pubDate>Tue, 03 Jan 2017 14:58:10 +0800</pubDate>
<guid>https://guangchuangyu.github.io/2017/01/convert-graphic-object-to-tree-object-using-treeio/</guid>
<description><p>I have splitted <code>ggtree</code> to 2 packages, <code>treeio</code> and <code>ggtree</code>. Now <code>ggtree</code> is mainly focus on visualization and annotation, while <code>treeio</code> focus on parsing and exporting tree files. Here is a welcome message from <code>treeio</code> that you can convert <code>ggtree</code> output to tree object which can be exported as newick or nexus file if you want.</p>
<p>Thanks to <code>ggplot2</code>, output of <code>ggtree</code> is actually a <code>ggplot</code> object. The <code>ggtree</code> object can be rendered as graph by <code>print</code> method, but internally it is an object that contains data. <code>treeio</code> defines <code>as.phylo</code> and <code>as.treedata</code> to convert <code>ggtree</code> object to <code>phylo</code> or <code>treedata</code> object.</p>
<p></p>
<pre><code>require(ggtree)
nhxfile &lt;- system.file(&quot;extdata/NHX&quot;, &quot;ADH.nhx&quot;, package=&quot;treeio&quot;)
nhx &lt;- read.nhx(nhxfile)
p &lt;- ggtree(nhx)
</code></pre>
<p>After parsing the NHX file via <code>read.nhx</code> function, we can visualize it using <code>ggtree</code>, and the output <code>ggtree</code> object can be converted back as a <code>phylo</code> object using <code>as.phylo</code> method:</p>
<blockquote>
<p>as.phylo(p)</p>
<p>Phylogenetic tree with 8 tips and 4 internal nodes.</p>
<p>Tip labels:
ADH2, ADH1, ADHY, ADHX, ADH4, ADH3, &hellip;</p>
<p>Rooted; includes branch lengths.</p>
</blockquote>
<p>The output <code>phylo</code> object contains the tree structure.</p>
<p>If we want to also save associated annotation data, we can use <code>as.treedata</code> method:</p>
<blockquote>
<p>as.treedata(p)</p>
<p>&lsquo;treedata&rsquo; S4 object that stored information of
&ldquo;.</p>
<p>&hellip;@ tree:
Phylogenetic tree with 8 tips and 4 internal nodes.</p>
<p>Tip labels:</p>
<p>ADH2, ADH1, ADHY, ADHX, ADH4, ADH3, &hellip;</p>
<p>Rooted; includes branch lengths.</p>
<p>with the following features available:
&rsquo;S&rsquo;, &rsquo;D&rsquo;, &lsquo;B&rsquo;.</p>
</blockquote>
<p>In <code>ggtree</code>, we can use <code>%&lt;+%</code> operator to attach user&rsquo;s own data to graphic object and then use it to annotate the tree. <code>as.treedata</code> can also export these attached data to the tree object.</p>
<blockquote>
<p>d = data.frame(label=as.phylo(nhx)$tip.label, <strong>trait</strong>=abs(rnorm(Ntip(nhx))))</p>
<p>p = p %&lt;+% d</p>
<p>as.treedata(p)</p>
<p>&lsquo;treedata&rsquo; S4 object that stored information of
&ldquo;.</p>
<p>&hellip;@ tree:</p>
<p>Phylogenetic tree with 8 tips and 4 internal nodes.</p>
<p>Tip labels:</p>
<p>ADH2, ADH1, ADHY, ADHX, ADH4, ADH3, &hellip;</p>
<p>Rooted; includes branch lengths.</p>
<p>with the following features available:
&rsquo;S&rsquo;, &rsquo;D&rsquo;, &lsquo;B&rsquo;, &lsquo;<strong>trait</strong>&rsquo;.</p>
</blockquote>
<p>Here as an example, the <strong>trait</strong> variable was attached and exported to the tree object.</p>
<p>This <strong>trait</strong> variable can also be used in tree annotation.</p>
<pre><code>x &lt;- as.treedata(p)
ggtree(x) + geom_tiplab(align=T, offset=.005) +