Browse code

update subview

guangchuang yu authored on 13/03/2017 05:39:11
Showing 5 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: ggtree
2 2
 Type: Package
3 3
 Title: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data
4
-Version: 1.7.9
4
+Version: 1.7.10
5 5
 Authors@R: c(
6 6
 	   person("Guangchuang", "Yu", email = "guangchuangyu@gmail.com", role = c("aut", "cre", "cph")),
7 7
 	   person("Tommy Tsan-Yuk", "Lam", email = "tylam.tommy@gmail.com", rol = c("aut", "ths")),
... ...
@@ -1,3 +1,7 @@
1
+CHANGES IN VERSION 1.7.10
2
+------------------------
3
+ o update subview to support mainview produced by `ggplot() + layers` <2017-03-13, Mon>
4
+
1 5
 CHANGES IN VERSION 1.7.9
2 6
 ------------------------
3 7
  o fixed geom_range to support height_0.95_HPD <2017-03-03, Fri>
... ...
@@ -1,6 +1,6 @@
1 1
 ##' add subview to mainview for ggplot2 objects
2 2
 ##'
3
-##' 
3
+##'
4 4
 ##' @title subview
5 5
 ##' @param mainview main view
6 6
 ##' @param subview a ggplot or grob object
... ...
@@ -11,15 +11,22 @@
11 11
 ##' @return ggplot object
12 12
 ##' @importFrom ggplot2 annotation_custom
13 13
 ##' @importFrom ggplot2 ggplotGrob
14
+##' @importFrom ggplot2 ggplot_build
14 15
 ##' @export
15 16
 ##' @author Guangchuang Yu
16 17
 subview <- function(mainview, subview, x, y, width=.1, height=.1) {
17 18
     mapping <- mainview$mapping %>% as.character
18 19
     aes_x <- mapping["x"]
19 20
     aes_y <- mapping["y"]
20
-    
21
-    xrng <- mainview$data[, aes_x] %>% range 
22
-    yrng <- mainview$data[, aes_y] %>% range
21
+
22
+    if (is.na(aes_x) || is.na(aes_y)) {
23
+        obj <- ggplot_build(mainview)
24
+        xrng <- obj$layout$panel_ranges[[1]]$x.range
25
+        yrng <- obj$layout$panel_ranges[[1]]$y.range
26
+    } else {
27
+        xrng <- mainview$data[, aes_x] %>% range
28
+        yrng <- mainview$data[, aes_y] %>% range
29
+    }
23 30
 
24 31
     for (i in seq_along(mainview$layers)) {
25 32
         layer <- mainview$layers[[i]]
... ...
@@ -58,11 +65,11 @@ subview <- function(mainview, subview, x, y, width=.1, height=.1) {
58 65
 
59 66
     xrng <- diff(xrng)
60 67
     yrng <- diff(yrng)
61
-    
68
+
62 69
     if (!any(class(subview) %in% c("ggplot", "grob", "character"))) {
63 70
         stop("subview should be a ggplot or grob object, or an image file...")
64 71
     }
65
-    
72
+
66 73
     if (is(subview, "ggplot")) {
67 74
         sv <- ggplotGrob(subview)
68 75
     } else if (is(subview, "grob")) {
... ...
@@ -76,7 +83,7 @@ subview <- function(mainview, subview, x, y, width=.1, height=.1) {
76 83
 
77 84
     width <- width/2
78 85
     height <- height/2
79
-    
86
+
80 87
     mainview + annotation_custom(
81 88
         sv,
82 89
         xmin = x - width*xrng,
... ...
@@ -19,7 +19,7 @@ library("ypages")
19 19
 
20 20
 
21 21
 `r badge_bioc_release("ggtree", "green")`
22
-`r badge_devel("ggtree", "green")`
22
+`r badge_devel("guangchuangyu/ggtree", "green")`
23 23
 [![Bioc](http://www.bioconductor.org/shields/years-in-bioc/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since)
24 24
 `r badge_bioc_download("ggtree", "total", "blue")`
25 25
 `r badge_bioc_download("ggtree", "month", "blue")`
... ...
@@ -4,9 +4,9 @@ ggtree: an R package for visualization and annotation of phylogenetic trees with
4 4
 
5 5
 <img src="https://raw.githubusercontent.com/jotsetung/BioC-stickers/master/ggtree/ggtree.png" height="128", align="right" />
6 6
 
7
-[![releaseVersion](https://img.shields.io/badge/release%20version-1.6.10-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.7.9-green.svg?style=flat)](https://github.com/ggtree) [![Bioc](http://www.bioconductor.org/shields/years-in-bioc/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [![total](https://img.shields.io/badge/downloads-12364/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-932/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
7
+[![](https://img.shields.io/badge/release%20version-1.6.10-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![](https://img.shields.io/badge/devel%20version-1.7.9-green.svg?style=flat)](https://github.com/guangchuangyu/ggtree) [![Bioc](http://www.bioconductor.org/shields/years-in-bioc/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [![](https://img.shields.io/badge/download-12746/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![](https://img.shields.io/badge/download-967/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
8 8
 
9
-[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![codecov](https://codecov.io/gh/GuangchuangYu/ggtree/branch/master/graph/badge.svg)](https://codecov.io/gh/GuangchuangYu/ggtree) [![Last-changedate](https://img.shields.io/badge/last%20change-2017--03--08-green.svg)](https://github.com/GuangchuangYu/ggtree/commits/master) [![GitHub forks](https://img.shields.io/github/forks/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/network) [![GitHub stars](https://img.shields.io/github/stars/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/stargazers) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://awesome-r.com/#awesome-r-graphic-displays)
9
+[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![codecov](https://codecov.io/gh/GuangchuangYu/ggtree/branch/master/graph/badge.svg)](https://codecov.io/gh/GuangchuangYu/ggtree) [![Last-changedate](https://img.shields.io/badge/last%20change-2017--03--13-green.svg)](https://github.com/GuangchuangYu/ggtree/commits/master) [![GitHub forks](https://img.shields.io/github/forks/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/network) [![GitHub stars](https://img.shields.io/github/stars/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/stargazers) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://awesome-r.com/#awesome-r-graphic-displays)
10 10
 
11 11
 [![platform](http://www.bioconductor.org/shields/availability/devel/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#archives) [![Build Status](http://www.bioconductor.org/shields/build/devel/bioc/ggtree.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/ggtree/) [![Linux/Mac Travis Build Status](https://img.shields.io/travis/GuangchuangYu/ggtree/master.svg?label=Mac%20OSX%20%26%20Linux)](https://travis-ci.org/GuangchuangYu/ggtree) [![AppVeyor Build Status](https://img.shields.io/appveyor/ci/Guangchuangyu/ggtree/master.svg?label=Windows)](https://ci.appveyor.com/project/GuangchuangYu/ggtree) [![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-green.svg?style=flat)](http://bioconda.github.io/recipes/bioconductor-ggtree/README.html)
12 12
 
... ...
@@ -20,7 +20,7 @@ Please cite the following article when using `ggtree`:
20 20
 
21 21
 **G Yu**, DK Smith, H Zhu, Y Guan, TTY Lam<sup>\*</sup>. 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.
22 22
 
23
-[![doi](https://img.shields.io/badge/doi-10.1111/2041--210X.12628-green.svg?style=flat)](http://dx.doi.org/10.1111/2041-210X.12628) [![citation](https://img.shields.io/badge/cited%20by-8-green.svg?style=flat)](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627) [![Altmetric](https://img.shields.io/badge/Altmetric-352-green.svg?style=flat)](https://www.altmetric.com/details/10533079)
23
+[![](https://img.shields.io/badge/doi-10.1111/2041--210X.12628-green.svg?style=flat)](http://dx.doi.org/10.1111/2041-210X.12628) [![citation](https://img.shields.io/badge/cited%20by-9-green.svg?style=flat)](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627) [![](https://img.shields.io/badge/Altmetric-351-green.svg?style=flat)](https://www.altmetric.com/details/10533079)
24 24
 
25 25
 ------------------------------------------------------------------------
26 26
 
... ...
@@ -33,32 +33,32 @@ For details, please visit our project website, <https://guangchuangyu.github.io/
33 33
 
34 34
 ### Citation
35 35
 
36
-[![citation](https://img.shields.io/badge/cited%20by-8-green.svg?style=flat)](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627)
36
+[![citation](https://img.shields.io/badge/cited%20by-9-green.svg?style=flat)](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627)
37 37
 
38 38
       +--+---------+---------+---------+---------+---------+---+
39
-    7 +                                                    *   +
39
+    8 +                                                    *   +
40
+      |                                                        |
40 41
       |                                                        |
41 42
     6 +                                                        +
42 43
       |                                                        |
43
-    5 +                                                        +
44 44
       |                                                        |
45 45
     4 +                                                        +
46
-    3 +                                                        +
47 46
       |                                                        |
48
-    2 +                                                        +
49 47
       |                                                        |
50
-    1 +  *                                                     +
48
+      |                                                        |
49
+    2 +                                                        +
50
+      |  *                                                     |
51 51
       +--+---------+---------+---------+---------+---------+---+
52 52
        2016     2016.2    2016.4    2016.6    2016.8     2017   
53 53
 
54 54
 ### Download stats
55 55
 
56
-[![download](http://www.bioconductor.org/shields/downloads/ggtree.svg)](https://bioconductor.org/packages/stats/bioc/ggtree) [![total](https://img.shields.io/badge/downloads-12364/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-932/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
56
+[![download](http://www.bioconductor.org/shields/downloads/ggtree.svg)](https://bioconductor.org/packages/stats/bioc/ggtree) [![](https://img.shields.io/badge/download-12746/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![](https://img.shields.io/badge/download-967/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
57 57
 
58 58
          ++-------------------+-------------------+--------------------+-------------------+-----------+
59 59
          |                                                                                    *        |
60
-         |                                                                              *              |
61
-         |                                                                                        *    |
60
+         |                                                                              *         *    |
61
+         |                                                                                             |
62 62
          |                                                                       *  *                  |
63 63
          |                                                                                             |
64 64
     1500 +                                                                                             +