Browse code

mv identify to ggfun

Guangchuang Yu authored on 01/04/2022 08:21:52
Showing 9 changed files

... ...
@@ -23,7 +23,7 @@ Depends:
23 23
     R (>= 3.5.0)
24 24
 Imports:
25 25
     ape,
26
-    aplot (>= 0.1.3),
26
+    aplot,
27 27
     dplyr,
28 28
     ggplot2 (>= 3.0.0),
29 29
     grid,
... ...
@@ -31,7 +31,7 @@ Imports:
31 31
     methods,
32 32
     purrr,
33 33
     rlang,
34
-    ggfun,
34
+    ggfun (>= 0.0.6),
35 35
     yulab.utils,
36 36
     tidyr,
37 37
     tidytree (>= 0.3.9),
... ...
@@ -37,7 +37,6 @@ S3method(ggplot_add,tree_inset)
37 37
 S3method(ggplot_add,zoom_clade)
38 38
 S3method(groupClade,ggtree)
39 39
 S3method(groupOTU,ggtree)
40
-S3method(identify,gg)
41 40
 S3method(nodeid,ggtree)
42 41
 S3method(nodelab,ggtree)
43 42
 S3method(offspring,ggtree)
... ...
@@ -108,6 +107,7 @@ export(groupOTU)
108 107
 export(guide_legend)
109 108
 export(gzoom)
110 109
 export(hexpand)
110
+export(identify)
111 111
 export(inset)
112 112
 export(label_pad)
113 113
 export(layout_circular)
... ...
@@ -173,6 +173,7 @@ importFrom(dplyr,mutate)
173 173
 importFrom(dplyr,rename)
174 174
 importFrom(dplyr,select)
175 175
 importFrom(ggfun,get_aes_var)
176
+importFrom(ggfun,identify)
176 177
 importFrom(ggplot2,Geom)
177 178
 importFrom(ggplot2,GeomLabel)
178 179
 importFrom(ggplot2,GeomPoint)
... ...
@@ -241,16 +242,11 @@ importFrom(ggplot2,xlab)
241 242
 importFrom(ggplot2,xlim)
242 243
 importFrom(ggplot2,ylab)
243 244
 importFrom(ggplot2,ylim)
244
-importFrom(graphics,identify)
245 245
 importFrom(grid,arrow)
246
-importFrom(grid,convertX)
247
-importFrom(grid,convertY)
248 246
 importFrom(grid,curveGrob)
249
-importFrom(grid,dataViewport)
250 247
 importFrom(grid,gTree)
251 248
 importFrom(grid,gpar)
252 249
 importFrom(grid,grid.layout)
253
-importFrom(grid,grid.locator)
254 250
 importFrom(grid,grid.newpage)
255 251
 importFrom(grid,grobTree)
256 252
 importFrom(grid,pushViewport)
... ...
@@ -27,7 +27,8 @@
27 27
 
28 28
 # ggtree 3.3.1.901
29 29
 
30
-+ update `identify.gg()` to support 'ggplot' object and `+xlim()` (2022-04-01, Fri)
30
++ mv `identify()` method to 'ggfun' (2022-04-01, Fri)
31
++ update `identify.gg()` to support 'ggplot' object and `+xlim()` 
31 32
 + update man files (2022-03-23, Wed, #489)
32 33
 
33 34
 # ggtree 3.3.1
... ...
@@ -159,7 +159,7 @@ ggplot_add.ggexpand <- function(object, plot, object_name) {
159 159
 }
160 160
 
161 161
 ggexpand_internal <- function(plot, ratio, direction, var) {
162
-    r <- ggrange(plot, var)
162
+    r <- ggfun::ggrange(plot, var)
163 163
     rr <- diff(r)
164 164
     if (direction == 1) {
165 165
         res <- r[2] + rr * ratio
166 166
deleted file mode 100644
... ...
@@ -1,61 +0,0 @@
1
-
2
-##' identify node by interactive click
3
-##'
4
-##'
5
-##' @rdname identify
6
-##' @title identify
7
-##' @param x tree view
8
-##' @param col selected columns to extract. Default is "auto" which will select all columns for 'ggplot' object and 'node' column for 'ggtree' object
9
-##' @param ... additional parameters, normally ignored
10
-##' @return closest data point
11
-##' @importFrom grid convertX
12
-##' @importFrom grid convertY
13
-##' @importFrom grid pushViewport
14
-##' @importFrom grid grid.locator
15
-##' @importFrom grid unit
16
-##' @importFrom grid dataViewport
17
-##' @importFrom graphics identify
18
-##' @importFrom ggplot2 last_plot
19
-##' @method identify gg
20
-##' @export
21
-##' @author Guangchuang Yu
22
-identify.gg <- function(x = last_plot(), col = "auto", ...) {
23
-    ## tree_view <- x
24
-    ## x=NULL, it will call graphics::identify
25
-
26
-    ## x <- tree_view$data$x
27
-    ## y <- tree_view$data$y
28
-
29
-    plot <- x
30
-    xvar <- ggfun::get_aes_var(plot$mapping, 'x')
31
-    yvar <- ggfun::get_aes_var(plot$mapping, 'y')
32
-    x <- plot$data[[xvar]]
33
-    y <- plot$data[[yvar]]
34
-
35
-    xlim <- aplot::xrange(plot)
36
-    ylim <- aplot::yrange(plot)
37
-    x <- c(x, rep(xlim, times = 2))
38
-    y <- c(y, rep(ylim, each = 2))
39
-
40
-    pushViewport(dataViewport(x, y))
41
-    loc <- grid.locator('in') %>% as.numeric
42
-
43
-    xx <- as.numeric(convertX( unit(x,'native'), 'in' ))
44
-    yy <- as.numeric(convertY( unit(y,'native'), 'in' ))
45
-
46
-    idx <- which.min( (xx-loc[1])^2 + (yy-loc[2])^2 )
47
-    res <- plot$data[idx,]
48
-    if (col == "auto" && inherits(plot, 'ggtree')) {
49
-        col <- 'node'
50
-    }
51
-    if (length(col) == 1 && col == "auto") {
52
-        return(res)
53
-    }
54
-
55
-    res <- res[,col]
56
-    if (length(col) == 1) {
57
-        res <- res[[1]]
58
-    }
59
-    return(res)
60
-}
61
-
... ...
@@ -106,3 +106,7 @@ grid::unit
106 106
 ##' @importFrom aplot plot_list
107 107
 ##' @export
108 108
 aplot::plot_list
109
+
110
+##' @importFrom ggfun identify
111
+##' @export
112
+ggfun::identify
... ...
@@ -175,5 +175,5 @@ message_wrap <- function(...){
175 175
 ## }
176 176
 
177 177
 
178
-ggrange <- getFromNamespace("ggrange", "aplot")
178
+
179 179
 
180 180
deleted file mode 100644
... ...
@@ -1,24 +0,0 @@
1
-% Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/method-identify.R
3
-\name{identify.gg}
4
-\alias{identify.gg}
5
-\title{identify}
6
-\usage{
7
-\method{identify}{gg}(x = last_plot(), col = "auto", ...)
8
-}
9
-\arguments{
10
-\item{x}{tree view}
11
-
12
-\item{col}{selected columns to extract. Default is "auto" which will select all columns for 'ggplot' object and 'node' column for 'ggtree' object}
13
-
14
-\item{...}{additional parameters, normally ignored}
15
-}
16
-\value{
17
-closest data point
18
-}
19
-\description{
20
-identify node by interactive click
21
-}
22
-\author{
23
-Guangchuang Yu
24
-}
... ...
@@ -30,6 +30,7 @@
30 30
 \alias{arrow}
31 31
 \alias{unit}
32 32
 \alias{plot_list}
33
+\alias{identify}
33 34
 \title{Objects exported from other packages}
34 35
 \keyword{internal}
35 36
 \description{
... ...
@@ -43,6 +44,8 @@ below to see their documentation.
43 44
 
44 45
   \item{dplyr}{\code{\link[dplyr:compute]{collapse}}}
45 46
 
47
+  \item{ggfun}{\code{\link[ggfun:reexports]{identify}}}
48
+
46 49
   \item{ggplot2}{\code{\link[ggplot2]{aes}}, \code{\link[ggplot2]{fortify}}, \code{\link[ggplot2:geom_text]{geom_label}}, \code{\link[ggplot2]{geom_point}}, \code{\link[ggplot2]{geom_text}}, \code{\link[ggplot2]{ggplot}}, \code{\link[ggplot2]{ggsave}}, \code{\link[ggplot2]{guide_legend}}, \code{\link[ggplot2:element]{margin}}, \code{\link[ggplot2:scale_manual]{scale_color_manual}}, \code{\link[ggplot2:scale_manual]{scale_colour_manual}}, \code{\link[ggplot2:scale_manual]{scale_fill_manual}}, \code{\link[ggplot2:scale_continuous]{scale_x_continuous}}, \code{\link[ggplot2]{theme}}, \code{\link[ggplot2:lims]{xlim}}}
47 50
 
48 51
   \item{grid}{\code{\link[grid]{arrow}}, \code{\link[grid]{unit}}}