Browse code

update docs

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@114602 bc3139a8-67e5-0310-9ffc-ced21a209358

Guangchuang Yu authored on 10/03/2016 11:55:44
Showing 9 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+add_range <- function(p, ...) {
2
+    df <- p$data
3
+    rr <- gsub("\\[", "", df$height_range)
4
+    rr <- gsub("\\]", "", rr)
5
+    rr2 <- strsplit(rr, split=',') %>% do.call('rbind', .)
6
+    rr2 <- matrix(as.numeric(rr2), ncol=2, byrow=FALSE)
7
+    ## if (!is.null(mrsd)) {
8
+    ##     mrsd %<>% as.Date
9
+    ##     date <- Date2decimal(mrsd)
10
+    ##     rr2 <- rr2 + date - max(rr2)
11
+    ##     if (asDate) {
12
+    ##         rr2 <- decimal2Date(rr2)
13
+    ##     }
14
+    ## }
15
+    rr2 <- rr2 + df$x - df$height
16
+    p + geom_segment2(x=rr2[,1], xend=rr2[,2], y=df$y, yend=df$y, ...)
17
+}
18
+
19
+## add range of height, only work with beast and only for height
20
+## when I have an idea of implementing such feature for all range
21
+## I will export it and make it usable for all users.
22
+##
23
+##
24
+## file <- system.file("extdata/BEAST", "beast_mcc.tree", package="ggtree")
25
+## beast <- read.beast(file)
26
+## p <- ggtree(beast)
27
+## add_range(p, color='firebrick', size=2, alpha=.3)
28
+##
29
+## p <- ggtree(beast, mrsd='2013-01-01') + theme_tree2()
30
+## add_range(p, color='firebrick', size=2, alpha=.3)
... ...
@@ -111,11 +111,13 @@ get_clade_position <- function(treeview, node) {
111 111
 
112 112
 get_clade_position_ <- function(data, node) {
113 113
     sp <- get.offspring.df(data, node)
114
-    sp.df <- data[c(sp, node),]
114
+    ## sp.df <- data[c(sp, node),]
115
+    sp <- c(sp, node)
116
+    sp.df <- data[match(sp, data$node),]
115 117
     x <- sp.df$x
116 118
     y <- sp.df$y
117 119
     if ("branch.length" %in% colnames(data)) {
118
-        xmin <- min(x)-data[node, "branch.length"]/2
120
+        xmin <- min(x)-data[match(node, data$node), "branch.length"]/2
119 121
     } else {
120 122
         xmin <- min(sp.df$branch)
121 123
     }
... ...
@@ -93,8 +93,9 @@ phylopic <- function(tree_view, phylopic_id,
93 93
             if (is.null(node)) {
94 94
                 stop("node or x and y should not be NULL...")
95 95
             }
96
-            x <- tree_view$data[node, "x"]
97
-            y <- tree_view$data[node, "y"]
96
+            df <- tree_view$data
97
+            x <- df[match(node, df$node), "x"]
98
+            y <- df[match(node, df$node), "y"]
98 99
         }
99 100
         AR <- getAR(img)
100 101
         xmin <- x - width/2
... ...
@@ -53,7 +53,7 @@ p <- p + geom_tiplab(size=3)
53 53
 gheatmap(p, genotype, offset = 2, width=0.5)
54 54
 ```
55 55
 
56
-The _width_ parameter is to control the width of the heatmap. It supports another parameter _offset_ for controling the distance between the tree and the heatmap, for instance to allocate space for tip labels.
56
+The _width_ parameter is to control the width of the heatmap. It supports another parameter _offset_ for controlling the distance between the tree and the heatmap, for instance to allocate space for tip labels.
57 57
 
58 58
 
59 59
 For time-scaled tree, as in this example, it's more often to use x axis by using `theme_tree2`. But with this solution, the heatmap is just another layer and will change the `x` axis. To overcome this issue, we implemented `scale_x_ggtree` to set the x axis more reasonable. 
60 60
new file mode 100644
61 61
Binary files /dev/null and b/vignettes/figures/ggtree_objects_v2.png differ
... ...
@@ -35,7 +35,7 @@ library("ggtree")
35 35
 
36 36
 # Rescale tree
37 37
 
38
-Most of the phylogenetic trees are scaled by evolutionary distance (substitution/site), in `ggtree`, users can re-scale a phylogenetic tree by any numerical variable inferred by evolutionary analysis (e.g. *dN/dS*).
38
+Most of the phylogenetic trees are scaled by evolutionary distance (substitution/site). In `ggtree`, users can re-scale a phylogenetic tree by any numerical variable inferred by evolutionary analysis (e.g. *dN/dS*).
39 39
 
40 40
 
41 41
 ```{r fig.width=10, fig.height=5}
... ...
@@ -251,7 +251,7 @@ print(dd)
251 251
 knitr::kable(dd)
252 252
 ```
253 253
 
254
-We can imaging that the _`place`_ column stores the location we isolated the species and _`value`_ column stores numerical values (e.g. bootstrap values).
254
+We can imaging that the _`place`_ column stores the location that we isolated the species and _`value`_ column stores numerical values (e.g. bootstrap values).
255 255
 
256 256
 We have demonstrated using the operator, _`%<%`_, to update a tree view with a new tree. Here, we will introduce another operator, _`%<+%`_, that attaches annotation data to a tree view. The only requirement of the input data is that its first column should be matched with the node/tip labels of the tree.
257 257
 
... ...
@@ -89,14 +89,14 @@ Correspondingly, `ggtree` defines several `S4` classes to store evolutionary evi
89 89
 + _`raxml`_ for storing output of `read.raxml()`
90 90
 
91 91
 
92
-The _`jplace`_ class is also designed to store user specified annotation data, and serves as a standard format for tree annotation within the `ggtree` package. 
92
+The _`jplace`_ class is also designed to store user specified annotation data.
93 93
 
94 94
 
95 95
 Here is an overview of these `S4` classes:
96 96
 
97
-![](figures/ggtree_objects.png)
97
+![](figures/ggtree_objects_v2.png)
98 98
 
99
-In addition, `ggtree` also supports _`phylo`_, _`multiPhylo`_ (defined by `ape`[@paradis_ape_2004]) and _`phylo4`_ (defined by `phylobase`).
99
+In addition, `ggtree` also supports _`phylo`_, _`multiPhylo`_ (defined by `ape`[@paradis_ape_2004]), _`phylo4`_ (defined by `phylobase`) _`obkData`_ (defined in `OutbreakTools`) and _`phyloseq`_ (defined in `phyloseq`).
100 100
 
101 101
 
102 102
 In `ggtree`, tree objects can be merged and evidences inferred from different phylogenetic analyses can be combined or compared and visualized.
... ...
@@ -104,7 +104,7 @@ In `ggtree`, tree objects can be merged and evidences inferred from different ph
104 104
 Viewing a phylogenetic tree in `ggtree` is easy by using the command `ggtree(tree_object)` and annotating a phylogenetic tree is simple by adding graphic layers using the grammar of graphics.
105 105
 
106 106
 
107
-For each class, we defined _`get.fields`_ method to get the annotation features that available in the object that can be used to annotate a phylogenetic tree directly in `ggtree`. A _`get.tree`_ method can be used to convert tree object to `phylo` object that are widely supported by other `R` packages. 
107
+For each class, we defined _`get.fields`_ method to get the annotation features that available in the object that can be used to annotate a phylogenetic tree directly in `ggtree`. A _`get.tree`_ method can be used to convert tree object to `phylo` (or `multiPhylo` for `r8s`) object that are widely supported by other `R` packages. 
108 108
 
109 109
 The _`groupOTU`_ method is used for clustering related OTUs (from tips to their most recent common ancestor). Related OTUs are not necessarily within a clade, they can be distantly related. _`groupOTU`_ works fine for monophyletic (clade), polyphyletic and paraphyletic, while _`groupClade`_ only works for clade (monophyletic). These methods are useful for clustering related OTUs or clades.
110 110
 
... ...
@@ -308,7 +308,7 @@ msaplot(phylip, offset=1)
308 308
 
309 309
 ## Parsing EPA and pplacer output
310 310
 
311
-[EPA](http://sco.h-its.org/exelixis/web/software/epa/index.html)[@berger_EPA_2011] and [PPLACER](http://matsen.fhcrc.org/pplacer/)[@matsen_pplacer_2010] have common output file format, `jplace`, which can be parse by `read.jplace()` function. 
311
+[EPA](http://sco.h-its.org/exelixis/web/software/epa/index.html)[@berger_EPA_2011] and [PPLACER](http://matsen.fhcrc.org/pplacer/)[@matsen_pplacer_2010] have common output file format, `jplace`, which can be parsed by `read.jplace()` function. 
312 312
 
313 313
 ```{r}
314 314
 jpf <- system.file("extdata/sample.jplace",  package="ggtree")
... ...
@@ -37,7 +37,7 @@ flip <- ggtree::flip
37 37
 
38 38
 # Internal node number
39 39
 
40
-Some of the functions in `ggtree` works with clade and accepts a parameter of internal node number. To get the internal node number, user can use `geom_text2` to display it:
40
+Some of the functions in `ggtree` work with clade and accept a parameter of internal node number. To get the internal node number, user can use `geom_text2` to display it:
41 41
 
42 42
 ```{r}
43 43
 nwk <- system.file("extdata", "sample.nwk", package="ggtree")
... ...
@@ -45,7 +45,7 @@ tree <- read.tree(nwk)
45 45
 ggtree(tree) + geom_text2(aes(subset=!isTip, label=node), hjust=-.3) + geom_tiplab()
46 46
 ```
47 47
 
48
-Another way to get the internal node number is using `MRCA()` function by providing a vector of taxa names. The function will return node number of input taxa's most recent commond ancestor (MRCA). It works with tree object and graphic object.
48
+Another way to get the internal node number is using `MRCA()` function by providing a vector of taxa names. The function will return node number of input taxa's most recent commond ancestor (MRCA). It works with tree and graphic object.
49 49
 
50 50
 
51 51
 ```{r}
... ...
@@ -67,9 +67,9 @@ viewClade(p+geom_tiplab(), node=21)
67 67
 
68 68
 # group Clades
69 69
 
70
-The `ggtree` package defined several functions to manipulate tree view. _`groupClade`_ and _`groupOTU`_ methods for clustering clades or related OTUs. _`groupClade`_ accepts an internal node or a vector of internal nodes to cluster clade/clades.
70
+The `ggtree` package defined several functions to manipulate tree view. _`groupClade`_ and _`groupOTU`_ methods were designed for clustering clades or related OTUs. _`groupClade`_ accepts an internal node or a vector of internal nodes to cluster clade/clades.
71 71
 
72
-Both _`groupClade`_ and _`groupOTU`_ work fine with tree object or tree view.
72
+Both _`groupClade`_ and _`groupOTU`_ work fine with tree and graphic object.
73 73
 
74 74
 ```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
75 75
 tree <- groupClade(tree, node=21)
... ...
@@ -32,7 +32,7 @@ library("ggtree")
32 32
 ```
33 33
 
34 34
 
35
-To view a phylogenetic tree, we first need to parse the tree file into `R`. The `ggtree` package supports many file format including output files of commonly used software packages in evolutionary biology. For more details, plase refer to the [Tree Data Import](treeImport.html) vignette.
35
+To view a phylogenetic tree, we first need to parse the tree file into `R`. The `ggtree` package supports many file formats including output files of commonly used software packages in evolutionary biology. For more details, plase refer to the [Tree Data Import](treeImport.html) vignette.
36 36
 
37 37
 ```{r}
38 38
 library("ggtree")
... ...
@@ -43,7 +43,7 @@ tree <- read.tree(nwk)
43 43
 # Viewing a phylogenetic tree with `ggtree`
44 44
 
45 45
 The `ggtree` package extends _`ggplot2`_ package to support viewing phylogenetic tree.
46
-It implements _`geom_tree`_ layer for displaying phylogenetic trees, as shown below:
46
+It implements _`geom_tree`_ layer for displaying phylogenetic tree, as shown below:
47 47
 
48 48
 
49 49
 ```{r fig.width=3, fig.height=3, fig.align="center"}
... ...
@@ -249,7 +249,7 @@ multiplot(
249 249
 
250 250
 # Visualize a list of trees
251 251
 
252
-`ggtree` supports `multiPhylo` object and a list of trees can be view simultaneously.
252
+`ggtree` supports `multiPhylo` object and a list of trees can be viewed simultaneously.
253 253
 
254 254
 ```{r fig.width=12, fig.height=4}
255 255
 trees <- lapply(c(10, 20, 40), rtree)