Skip to content

Commit 015cdc1

Browse files
committed
Also boilerplate stat_manual()
1 parent 9ca4353 commit 015cdc1

File tree

1 file changed

+18
-46
lines changed

1 file changed

+18
-46
lines changed

R/stat-manual.R

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
#' @rdname ggplot2-ggproto
2+
#' @format NULL
3+
#' @usage NULL
4+
#' @export
5+
StatManual <- ggproto(
6+
"StatManual", Stat,
7+
8+
setup_params = function(data, params) {
9+
params$fun <- allow_lambda(params$fun)
10+
check_function(params$fun, arg = "fun")
11+
params
12+
},
13+
14+
compute_group = function(data, scales, fun = identity, args = list()) {
15+
as_gg_data_frame(inject(fun(data, !!!args)))
16+
}
17+
)
118

219
#' Manually compute transformations
320
#'
@@ -83,49 +100,4 @@
83100
#' args = vars(hull = chull(x, y), x = x[hull], y = y[hull])
84101
#' )
85102
#' }
86-
stat_manual <- function(
87-
mapping = NULL,
88-
data = NULL,
89-
geom = "point",
90-
position = "identity",
91-
...,
92-
fun = identity,
93-
args = list(),
94-
na.rm = FALSE,
95-
show.legend = NA,
96-
inherit.aes = TRUE) {
97-
98-
layer(
99-
data = data,
100-
mapping = mapping,
101-
stat = StatManual,
102-
geom = geom,
103-
position = position,
104-
show.legend = show.legend,
105-
inherit.aes = inherit.aes,
106-
params = list2(
107-
na.rm = na.rm,
108-
fun = fun,
109-
args = args,
110-
...
111-
)
112-
)
113-
}
114-
115-
#' @rdname ggplot2-ggproto
116-
#' @format NULL
117-
#' @usage NULL
118-
#' @export
119-
StatManual <- ggproto(
120-
"StatManual", Stat,
121-
122-
setup_params = function(data, params) {
123-
params$fun <- allow_lambda(params$fun)
124-
check_function(params$fun, arg = "fun")
125-
params
126-
},
127-
128-
compute_group = function(data, scales, fun = identity, args = list()) {
129-
as_gg_data_frame(inject(fun(data, !!!args)))
130-
}
131-
)
103+
stat_manual <- make_constructor(StatManual, geom = "point")

0 commit comments

Comments
 (0)