Browse code

Merge remote-tracking branch 'upstream/master'

xiangpin authored on 12/08/2022 12:54:09
Showing 5 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: ggtree
2 2
 Type: Package
3 3
 Title: an R package for visualization of tree and annotation data
4
-Version: 3.5.1.902
4
+Version: 3.5.2
5 5
 Authors@R: c(
6 6
        person("Guangchuang", "Yu",     email = "guangchuangyu@gmail.com", role = c("aut", "cre", "cph"), 
7 7
             comment = c(ORCID = "0000-0002-6485-8781")),
... ...
@@ -37,7 +37,8 @@ Imports:
37 37
     tidytree (>= 0.3.9),
38 38
     treeio (>= 1.8.0),
39 39
     utils,
40
-    scales
40
+    scales,
41
+    stats
41 42
 Suggests:
42 43
     emojifont,
43 44
     ggimage,
... ...
@@ -47,7 +48,6 @@ Suggests:
47 48
     knitr,
48 49
     prettydoc,
49 50
     rmarkdown,
50
-    stats,
51 51
     testthat,
52 52
     tibble,
53 53
     glue
... ...
@@ -62,5 +62,5 @@ BugReports: https://github.com/YuLab-SMU/ggtree/issues
62 62
 Packaged: 2014-12-03 08:16:14 UTC; root
63 63
 biocViews: Alignment, Annotation, Clustering, DataImport,
64 64
     MultipleSequenceAlignment, Phylogenetics, ReproducibleResearch, Software, Visualization
65
-RoxygenNote: 7.2.0
65
+RoxygenNote: 7.2.1
66 66
 Roxygen: list(markdown = TRUE)
... ...
@@ -7,6 +7,7 @@ S3method(fortify,dendrogram)
7 7
 S3method(fortify,diana)
8 8
 S3method(fortify,hclust)
9 9
 S3method(fortify,igraph)
10
+S3method(fortify,linkage)
10 11
 S3method(fortify,multiPhylo)
11 12
 S3method(fortify,obkData)
12 13
 S3method(fortify,phylo)
... ...
@@ -268,6 +269,8 @@ importFrom(rlang,abort)
268 269
 importFrom(rlang,as_name)
269 270
 importFrom(rlang,quo_name)
270 271
 importFrom(scales,alpha)
272
+importFrom(stats,as.hclust)
273
+importFrom(stats,cutree)
271 274
 importFrom(tidyr,gather)
272 275
 importFrom(tidytree,MRCA)
273 276
 importFrom(tidytree,ancestor)
... ...
@@ -25,8 +25,10 @@
25 25
 
26 26
 -->
27 27
 
28
-# ggtree 3.5.1.902
28
+# ggtree 3.5.2
29 29
 
30
++ `scale_color_subtree()` now supports passing a numeric value and internally it will call `cutree(tree, k)` (2022-08-11, Thu)
31
++ support 'linkage' class defined in the 'mdendro' package (2022-08-11, Thu)
30 32
 + clone the plot environment before assigning layout (2022-07-19, Tue, #516)
31 33
 + bug fixed in 'equal_angle' layout (2022-07-08, Fri, #514)
32 34
 + optimize `geom_tiplab` to better compatible with dendrogram layout (2022-06-23, Thu, #508)
... ...
@@ -135,7 +135,8 @@ fortify.phylo4 <- function(model, data,
135 135
                            mrsd      = NULL,
136 136
                            hang      = .1,
137 137
                            ...) {
138
-    if (inherits(model, c("dendrogram", "agnes", "diana", "twins"))) {
138
+    if (inherits(model, c("dendrogram", "linkage", 
139
+                        "agnes", "diana", "twins"))) {
139 140
         model <- stats::as.hclust(model)
140 141
     }
141 142
 
... ...
@@ -190,6 +191,9 @@ fortify.phylog <- fortify.phylo4
190 191
 ##' @export
191 192
 fortify.igraph <- fortify.phylo4
192 193
 
194
+##' @method fortify linkage
195
+##' @export
196
+fortify.linkage <- fortify.phylo4
193 197
 
194 198
 ##' @method fortify phylo4d
195 199
 ##' @importFrom treeio as.treedata
... ...
@@ -10,7 +10,7 @@
10 10
 scale_color_subtree <- function(group) {
11 11
     if (inherits(group, 'kmeans')) {
12 12
         group <- group$cluster
13
-    }
13
+    } 
14 14
 
15 15
     structure(group,
16 16
               class = 'color_subtree'
... ...
@@ -18,10 +18,17 @@ scale_color_subtree <- function(group) {
18 18
 }
19 19
 
20 20
 ##' @rdname scale-color-subtree
21
+##' @importFrom stats as.hclust
22
+##' @importFrom stats cutree
21 23
 ##' @export
22 24
 scale_colour_subtree <- scale_color_subtree
23 25
 
24
-scale_color_subtree_ <- function(p, group) {    
26
+scale_color_subtree_ <- function(p, group) {
27
+
28
+    if (is.numeric(group) && length(group) == 1) {
29
+        group <- cutree(as.hclust(as.phylo(p$data)), group)
30
+    } 
31
+
25 32
     g <- split(names(group), group)
26 33
     groupOTU(p, g, group_name = 'subtree') +
27 34
         aes_(color = ~subtree)