Browse code

xlim_tree

guangchuang yu authored on 31/10/2016 07:41:12
Showing11 changed files

... ...
@@ -117,7 +117,6 @@ export(rtree)
117 117
 export(scaleClade)
118 118
 export(scale_color)
119 119
 export(scale_x_ggtree)
120
-export(set_tree_xlim)
121 120
 export(stat_balance)
122 121
 export(stat_hilight)
123 122
 export(subview)
... ...
@@ -127,6 +126,7 @@ export(theme_tree)
127 126
 export(theme_tree2)
128 127
 export(viewClade)
129 128
 export(write.jplace)
129
+export(xlim_tree)
130 130
 exportClasses(apeBootstrap)
131 131
 exportClasses(beast)
132 132
 exportClasses(codeml)
... ...
@@ -1,6 +1,6 @@
1 1
 CHANGES IN VERSION 1.7.1
2 2
 ------------------------
3
- o set_tree_xlim function and test <2016-10-31, Mon>
3
+ o xlim_tree layer and test <2016-10-31, Mon>
4 4
    + set x axis limit for Tree panel for facet_plot
5 5
  o update read.nhx <2016-10-30, Sun>
6 6
    + add tip numbers to @nhx_tags and add tests
... ...
@@ -31,25 +31,14 @@ add_panel <- function(p, panel) {
31 31
 ##' set x axis limits for Tree panel
32 32
 ##'
33 33
 ##'
34
-##' @title set_tree_xlim
35
-##' @param tree_view tree view
34
+##' @title xlim_tree
36 35
 ##' @param xlim xlim, should be of length 2
37 36
 ##' @return updated tree view
38 37
 ##' @export
39 38
 ##' @importFrom ggplot2 geom_blank
40 39
 ##' @author guangchuang yu
41
-set_tree_xlim <- function(tree_view, xlim) {
42
-    if (length(xlim) != 2) {
43
-        stop('-> xlim should be of length 2...')
44
-    }
45
-    x <- tree_view$data$x
46
-    if (is.na(xlim[1])) {
47
-        xlim[1] <- min(x)
48
-    }
49
-    if (is.na(xlim[2])) {
50
-        xlim[2] <- max(x)
51
-    }
40
+xlim_tree <- function(xlim) {
52 41
     dummy <- data.frame(x=xlim, panel='Tree')
53
-    tree_view + geom_blank(aes(x=x), dummy, inherit.aes = FALSE)
42
+    geom_blank(aes_(x=~x), dummy, inherit.aes = FALSE)
54 43
 }
55 44
 
... ...
@@ -195,8 +195,6 @@
195 195
         
196 196
             <li><a href="#application"> Application</a></li>
197 197
         
198
-            <li><a href="#helper-functions"> Helper functions</a></li>
199
-        
200 198
             <li><a href="#funny-stuff"> Funny stuff</a></li>
201 199
         
202 200
             <li><a href="#users-feedback"> User's feedback</a></li>
... ...
@@ -265,6 +263,7 @@
265 263
 <ul>
266 264
 <li><a href="https://guangchuangyu.github.io/2015/02/ggtree---updating-a-tree-view/">ggtree - updating a tree view</a></li>
267 265
 <li><a href="https://guangchuangyu.github.io/2015/04/an-example-of-drawing-beast-tree-using-ggtree">an example of drawing beast tree using ggtree</a></li>
266
+<li><a href="https://guangchuangyu.github.io/2016/10/xlim_tree-set-x-axis-limits-for-only-tree-panel/">xlim_tree: set x axis limits for only Tree panel</a></li>
268 267
 </ul>
269 268
 <h3 id="tree-annotation"><i class="fa fa-angle-double-right"></i> Tree annotation</h3>
270 269
 <ul>
... ...
@@ -287,10 +286,6 @@
287 286
 <li><a href="https://github.com/GuangchuangYu/plotTree-ggtree">ggtree version of plotTree.R</a></li>
288 287
 <li><a href="https://guangchuangyu.github.io/2016/10/reproducible-logo-generated-by-ggtree">reproducible logo generated by ggtree</a></li>
289 288
 </ul>
290
-<h3 id="helper-functions"><i class="fa fa-angle-double-right"></i> Helper functions</h3>
291
-<ul>
292
-<li><a href="https://guangchuangyu.github.io/2016/10/set_tree_xlim-set-x-axis-limits-for-only-tree-panel/">set_tree_xlim: set x axis limits for only Tree panel</a></li>
293
-</ul>
294 289
 <h3 id="funny-stuff"><i class="fa fa-angle-double-right"></i> Funny stuff</h3>
295 290
 <ul>
296 291
 <li><a href="https://guangchuangyu.github.io/2015/06/ggtree-with-funny-fonts">ggtree with funny fonts</a></li>
... ...
@@ -223,11 +223,11 @@
223 223
   }  
224 224
   </style>
225 225
 
226
-<div id = 'chart19ad646a81f1' class = 'rChart morris'></div>
226
+<div id = 'chart371c6b358a50' class = 'rChart morris'></div>
227 227
 
228 228
 <script type='text/javascript'>
229 229
     var chartParams = {
230
- "element": "chart19ad646a81f1",
230
+ "element": "chart371c6b358a50",
231 231
 "width":            800,
232 232
 "height":            400,
233 233
 "xkey": "year",
... ...
@@ -241,7 +241,7 @@
241 241
 "pubid": "HtEfBTGE9r8C" 
242 242
 } 
243 243
 ],
244
-"id": "chart19ad646a81f1",
244
+"id": "chart371c6b358a50",
245 245
 "labels": "cites" 
246 246
 },
247 247
       chartType = "Bar"
... ...
@@ -67,7 +67,7 @@
67 67
         }, 
68 68
         {
69 69
             "location": "/documentation/", 
70
-            "text": "Vignettes\n\n\n\n\nggtree\n\n\nTree Data Import\n\n\nTree Visualization\n\n\nTree Annotation\n\n\nTree Manipulation\n\n\nAdvance Tree Annotation\n\n\nggtree utilities\n\n\n\n\n Blog posts\n\n\n News and updates\n\n\n\n\nviewing and annotating phylogenetic tree with ggtree\n\n\nggtree in Bioconductor 3.1\n\n\nBioC 3.1: NEWS of my BioC packages\n\n\nBioC 3.2: NEWS of my BioC packages\n\n\nNews of ggtree\n\n\nBioC 3.3: NEWS of my BioC packages\n\n\nBioC 3.4: NEWS of my BioC packages\n\n\nggtree paper published\n\n\n\n\n Data manipulation\n\n\n\n\nsubsetting data in ggtree\n\n\nggtree supports phylip tree format\n\n\n\n\n Tree visualization\n\n\n\n\nggtree - updating a tree view\n\n\nan example of drawing beast tree using ggtree\n\n\n\n\n Tree annotation\n\n\n\n\nlabel edge number in ggtree\n\n\nsubview\n\n\nAnnotate a phylogenetic tree with insets\n\n\nggtree annotate phylogenetic tree with local images\n\n\nembed images in ggplot2 via subview and annotate a phylogenetic tree with images using inset function\n\n\nidentify method for ggtree\n\n\nfacet_plot: a general solution to associate data with phylogenetic tree\n\n\n\n\n Tree manipulation\n\n\n\n\nflip and rotate branches in ggtree\n\n\n\n\n Application\n\n\n\n\nggtree for microbiome data\n\n\nggtree for outbreak data\n\n\nggtree version of plotTree.R\n\n\nreproducible logo generated by ggtree\n\n\n\n\n Helper functions\n\n\n\n\nset_tree_xlim: set x axis limits for only Tree panel\n\n\n\n\n Funny stuff\n\n\n\n\nggtree with funny fonts\n\n\ncomic phylogenetic tree with ggtree and comicR\n\n\nuse emoji font in R\n\n\n\n\n User's feedback\n\n\n\n\ntweets of ggtree\n\n\nJoin the group chat on \n and \n\n\n\n\n Find out more on \nhttps://guangchuangyu.github.io/tags/ggtree/\n.\n\n\n Slides\n\n\n\n\nGenerating publication quality figures using R \n ggplot2\n\n\nggtree for visualization and annotation of phylogenetic trees\n\n\n\n\n Video\n\n\n\n\ninteractive clade highlighting\n\n\ninteractive rotating clades\n\n\ninteractive clade labeling\n\n\n\n\n Workflow\n\n\n\n\nrecreate a tree from a publication (\nBloom\n \net al\n, \nScience\n 2010)", 
70
+            "text": "Vignettes\n\n\n\n\nggtree\n\n\nTree Data Import\n\n\nTree Visualization\n\n\nTree Annotation\n\n\nTree Manipulation\n\n\nAdvance Tree Annotation\n\n\nggtree utilities\n\n\n\n\n Blog posts\n\n\n News and updates\n\n\n\n\nviewing and annotating phylogenetic tree with ggtree\n\n\nggtree in Bioconductor 3.1\n\n\nBioC 3.1: NEWS of my BioC packages\n\n\nBioC 3.2: NEWS of my BioC packages\n\n\nNews of ggtree\n\n\nBioC 3.3: NEWS of my BioC packages\n\n\nBioC 3.4: NEWS of my BioC packages\n\n\nggtree paper published\n\n\n\n\n Data manipulation\n\n\n\n\nsubsetting data in ggtree\n\n\nggtree supports phylip tree format\n\n\n\n\n Tree visualization\n\n\n\n\nggtree - updating a tree view\n\n\nan example of drawing beast tree using ggtree\n\n\nxlim_tree: set x axis limits for only Tree panel\n\n\n\n\n Tree annotation\n\n\n\n\nlabel edge number in ggtree\n\n\nsubview\n\n\nAnnotate a phylogenetic tree with insets\n\n\nggtree annotate phylogenetic tree with local images\n\n\nembed images in ggplot2 via subview and annotate a phylogenetic tree with images using inset function\n\n\nidentify method for ggtree\n\n\nfacet_plot: a general solution to associate data with phylogenetic tree\n\n\n\n\n Tree manipulation\n\n\n\n\nflip and rotate branches in ggtree\n\n\n\n\n Application\n\n\n\n\nggtree for microbiome data\n\n\nggtree for outbreak data\n\n\nggtree version of plotTree.R\n\n\nreproducible logo generated by ggtree\n\n\n\n\n Funny stuff\n\n\n\n\nggtree with funny fonts\n\n\ncomic phylogenetic tree with ggtree and comicR\n\n\nuse emoji font in R\n\n\n\n\n User's feedback\n\n\n\n\ntweets of ggtree\n\n\nJoin the group chat on \n and \n\n\n\n\n Find out more on \nhttps://guangchuangyu.github.io/tags/ggtree/\n.\n\n\n Slides\n\n\n\n\nGenerating publication quality figures using R \n ggplot2\n\n\nggtree for visualization and annotation of phylogenetic trees\n\n\n\n\n Video\n\n\n\n\ninteractive clade highlighting\n\n\ninteractive rotating clades\n\n\ninteractive clade labeling\n\n\n\n\n Workflow\n\n\n\n\nrecreate a tree from a publication (\nBloom\n \net al\n, \nScience\n 2010)", 
71 71
             "title": "Documentation"
72 72
         }, 
73 73
         {
... ...
@@ -92,7 +92,7 @@
92 92
         }, 
93 93
         {
94 94
             "location": "/documentation/#tree-visualization", 
95
-            "text": "ggtree - updating a tree view  an example of drawing beast tree using ggtree", 
95
+            "text": "ggtree - updating a tree view  an example of drawing beast tree using ggtree  xlim_tree: set x axis limits for only Tree panel", 
96 96
             "title": " Tree visualization"
97 97
         }, 
98 98
         {
... ...
@@ -110,11 +110,6 @@
110 110
             "text": "ggtree for microbiome data  ggtree for outbreak data  ggtree version of plotTree.R  reproducible logo generated by ggtree", 
111 111
             "title": " Application"
112 112
         }, 
113
-        {
114
-            "location": "/documentation/#helper-functions", 
115
-            "text": "set_tree_xlim: set x axis limits for only Tree panel", 
116
-            "title": " Helper functions"
117
-        }, 
118 113
         {
119 114
             "location": "/documentation/#funny-stuff", 
120 115
             "text": "ggtree with funny fonts  comic phylogenetic tree with ggtree and comicR  use emoji font in R", 
... ...
@@ -202,7 +197,7 @@
202 197
         }, 
203 198
         {
204 199
             "location": "/featuredArticles/", 
205
-            "text": "Let us know\n if you have published using \nggtree\n and your publication will be featured here.\n\n\n\n\n\n\n\n\n\n\n\n\n\n  .rChart {\n    display: block;\n    margin-left: auto; \n    margin-right: auto;\n    width: 800px;\n    height: 300px;\n  }  \n  \n\n\n\n\n\n\n\n    var chartParams = {\n \"element\": \"chart19ad646a81f1\",\n\"width\":            800,\n\"height\":            400,\n\"xkey\": \"year\",\n\"ykeys\": [\n \"cites\" \n],\n\"data\": [\n {\n \"year\": 2016,\n\"cites\":              1,\n\"pubid\": \"HtEfBTGE9r8C\" \n} \n],\n\"id\": \"chart19ad646a81f1\",\n\"labels\": \"cites\" \n},\n      chartType = \"Bar\"\n    new Morris[chartType](chartParams)\n\n\n\n\n 2016\n\n\nLack of GLYCOLATE OXIDASE 1, but not GLYCOLATE OXIDASE 2, attenuates the photorespiratory phenotype of CATALASE2-deficient \nArabidopsis\n\n\nPlant Physiology\n May. 2016 \n\n\n\n\nRange overlap drives chromosome inversion fixation in passerine birds\n\n\nbioRxiv\n May. 2016 \nhttp://dx.doi.org/10.1101/053371\n\n\n\n\nPhenotypic and Genotypic Characteristics of Shiga Toxin-Producing Escherichia coli Isolated from Surface Waters and Sediments in a Canadian Urban-Agricultural Landscape\n\n\nFront. Cell. Infect. Microbiol.\n Apr. 2016 \nhttp://dx.doi.org/10.3389%2Ffcimb.2016.00036\n\n\n\n\nWs-2\n Introgression in a Proportion of \nArabidopsis thaliana Col-0\n Stock Seed Produces Specific Phenotypes and Highlights the Importance of Routine Genetic Verification\n\n\nPlant Cell\n Mar. 2016 \nhttp://dx.doi.org/10.1105/tpc.16.00053\n\n\n\n\n 2015\n\n\nThe population genetics of drug resistance evolution in natural populations of viral, bacterial and eukaryotic pathogens\n\n\nMolecuar Ecology\n Dec. 2015 \nhttp://dx.doi.org/10.1111/mec.13474\n\n\n\n\nGenetic characterization of highly pathogenic H5 influenza viruses from poultry in Taiwan, 2015\n\n\nInfection, Genetics and Evolution\n Dec. 2015 \nhttp://dx.doi.org/10.1016/j.meegid.2015.12.006\n\n\n\n\nTrans-species polymorphism at antimicrobial innate immunity cathelicidin genes of Atlantic cod and related species\n\n\nPeerJ\n May 2015 \nhttps://doi.org/10.7717/peerj.976", 
200
+            "text": "Let us know\n if you have published using \nggtree\n and your publication will be featured here.\n\n\n\n\n\n\n\n\n\n\n\n\n\n  .rChart {\n    display: block;\n    margin-left: auto; \n    margin-right: auto;\n    width: 800px;\n    height: 300px;\n  }  \n  \n\n\n\n\n\n\n\n    var chartParams = {\n \"element\": \"chart371c6b358a50\",\n\"width\":            800,\n\"height\":            400,\n\"xkey\": \"year\",\n\"ykeys\": [\n \"cites\" \n],\n\"data\": [\n {\n \"year\": 2016,\n\"cites\":              1,\n\"pubid\": \"HtEfBTGE9r8C\" \n} \n],\n\"id\": \"chart371c6b358a50\",\n\"labels\": \"cites\" \n},\n      chartType = \"Bar\"\n    new Morris[chartType](chartParams)\n\n\n\n\n 2016\n\n\nLack of GLYCOLATE OXIDASE 1, but not GLYCOLATE OXIDASE 2, attenuates the photorespiratory phenotype of CATALASE2-deficient \nArabidopsis\n\n\nPlant Physiology\n May. 2016 \n\n\n\n\nRange overlap drives chromosome inversion fixation in passerine birds\n\n\nbioRxiv\n May. 2016 \nhttp://dx.doi.org/10.1101/053371\n\n\n\n\nPhenotypic and Genotypic Characteristics of Shiga Toxin-Producing Escherichia coli Isolated from Surface Waters and Sediments in a Canadian Urban-Agricultural Landscape\n\n\nFront. Cell. Infect. Microbiol.\n Apr. 2016 \nhttp://dx.doi.org/10.3389%2Ffcimb.2016.00036\n\n\n\n\nWs-2\n Introgression in a Proportion of \nArabidopsis thaliana Col-0\n Stock Seed Produces Specific Phenotypes and Highlights the Importance of Routine Genetic Verification\n\n\nPlant Cell\n Mar. 2016 \nhttp://dx.doi.org/10.1105/tpc.16.00053\n\n\n\n\n 2015\n\n\nThe population genetics of drug resistance evolution in natural populations of viral, bacterial and eukaryotic pathogens\n\n\nMolecuar Ecology\n Dec. 2015 \nhttp://dx.doi.org/10.1111/mec.13474\n\n\n\n\nGenetic characterization of highly pathogenic H5 influenza viruses from poultry in Taiwan, 2015\n\n\nInfection, Genetics and Evolution\n Dec. 2015 \nhttp://dx.doi.org/10.1016/j.meegid.2015.12.006\n\n\n\n\nTrans-species polymorphism at antimicrobial innate immunity cathelicidin genes of Atlantic cod and related species\n\n\nPeerJ\n May 2015 \nhttps://doi.org/10.7717/peerj.976", 
206 201
             "title": "Featured Articles"
207 202
         }, 
208 203
         {
209 204
similarity index 67%
210 205
rename from man/set_tree_xlim.Rd
211 206
rename to man/xlim_tree.Rd
... ...
@@ -1,14 +1,12 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/facet_plot.R
3
-\name{set_tree_xlim}
4
-\alias{set_tree_xlim}
5
-\title{set_tree_xlim}
3
+\name{xlim_tree}
4
+\alias{xlim_tree}
5
+\title{xlim_tree}
6 6
 \usage{
7
-set_tree_xlim(tree_view, xlim)
7
+xlim_tree(xlim)
8 8
 }
9 9
 \arguments{
10
-\item{tree_view}{tree view}
11
-
12 10
 \item{xlim}{xlim, should be of length 2}
13 11
 }
14 12
 \value{
... ...
@@ -48,6 +48,8 @@
48 48
 
49 49
 + [ggtree - updating a tree view](https://guangchuangyu.github.io/2015/02/ggtree---updating-a-tree-view/)
50 50
 + [an example of drawing beast tree using ggtree](https://guangchuangyu.github.io/2015/04/an-example-of-drawing-beast-tree-using-ggtree)
51
++ [xlim_tree: set x axis limits for only Tree panel](https://guangchuangyu.github.io/2016/10/xlim_tree-set-x-axis-limits-for-only-tree-panel/)
52
+
51 53
 
52 54
 ### <i class="fa fa-angle-double-right"></i> Tree annotation
53 55
 
... ...
@@ -70,9 +72,6 @@
70 72
 + [ggtree version of plotTree.R](https://github.com/GuangchuangYu/plotTree-ggtree)
71 73
 + [reproducible logo generated by ggtree](https://guangchuangyu.github.io/2016/10/reproducible-logo-generated-by-ggtree)
72 74
 
73
-### <i class="fa fa-angle-double-right"></i> Helper functions
74
-
75
-+ [set_tree_xlim: set x axis limits for only Tree panel](https://guangchuangyu.github.io/2016/10/set_tree_xlim-set-x-axis-limits-for-only-tree-panel/)
76 75
 
77 76
 ### <i class="fa fa-angle-double-right"></i> Funny stuff
78 77
 
... ...
@@ -36,10 +36,10 @@
36 36
   }  
37 37
   </style>
38 38
 
39
-<div id = 'chart19ad646a81f1' class = 'rChart morris'></div>
39
+<div id = 'chart371c6b358a50' class = 'rChart morris'></div>
40 40
 <script type='text/javascript'>
41 41
     var chartParams = {
42
- "element": "chart19ad646a81f1",
42
+ "element": "chart371c6b358a50",
43 43
 "width":            800,
44 44
 "height":            400,
45 45
 "xkey": "year",
... ...
@@ -53,7 +53,7 @@
53 53
 "pubid": "HtEfBTGE9r8C" 
54 54
 } 
55 55
 ],
56
-"id": "chart19ad646a81f1",
56
+"id": "chart371c6b358a50",
57 57
 "labels": "cites" 
58 58
 },
59 59
       chartType = "Bar"
... ...
@@ -35,6 +35,8 @@
35 35
 
36 36
 + [ggtree - updating a tree view](https://guangchuangyu.github.io/2015/02/ggtree---updating-a-tree-view/)
37 37
 + [an example of drawing beast tree using ggtree](https://guangchuangyu.github.io/2015/04/an-example-of-drawing-beast-tree-using-ggtree)
38
++ [xlim_tree: set x axis limits for only Tree panel](https://guangchuangyu.github.io/2016/10/xlim_tree-set-x-axis-limits-for-only-tree-panel/)
39
+
38 40
 
39 41
 ### <i class="fa fa-angle-double-right"></i> Tree annotation
40 42
 
... ...
@@ -57,9 +59,6 @@
57 59
 + [ggtree version of plotTree.R](https://github.com/GuangchuangYu/plotTree-ggtree)
58 60
 + [reproducible logo generated by ggtree](https://guangchuangyu.github.io/2016/10/reproducible-logo-generated-by-ggtree)
59 61
 
60
-### <i class="fa fa-angle-double-right"></i> Helper functions
61
-
62
-+ [set_tree_xlim: set x axis limits for only Tree panel](https://guangchuangyu.github.io/2016/10/set_tree_xlim-set-x-axis-limits-for-only-tree-panel/)
63 62
 
64 63
 ### <i class="fa fa-angle-double-right"></i> Funny stuff
65 64
 
66 65
similarity index 63%
67 66
rename from tests/testthat/test-set_tree_xlim.R
68 67
rename to tests/testthat/test-xlim_tree.R
... ...
@@ -1,4 +1,4 @@
1
-context("set_tree_xlim")
1
+context("xlim_tree")
2 2
 
3 3
 test_that("dummy layer to set x axis limits of Tree panel", {
4 4
     set.seed(2016-10-31)
... ...
@@ -8,7 +8,7 @@ test_that("dummy layer to set x axis limits of Tree panel", {
8 8
 
9 9
     d <- data.frame(id = tr$tip.label, v= rnorm(50))
10 10
 
11
-    p2 <- facet_plot(set_tree_xlim(p, c(NA, 6)), geom=geom_point, data=d, mapping=aes(x=v), panel='dot') + ggtitle('*set_tree_xlim* only change x axis limits of *Tree* panel')
11
+    p2 <- facet_plot(p + xlim_tree(c(NA, 6)), geom=geom_point, data=d, mapping=aes(x=v), panel='dot') + ggtitle('*set_tree_xlim* only change x axis limits of *Tree* panel')
12 12
 
13 13
     expect_true(is.ggplot(p2)) # should plot appropriately
14 14
 })