Skip to content

Commit e3043ae

Browse files
Merge pull request plotly#2042 from moutikabdessabour/implement_geomFunction
Closes plotly#1872. Implemented to_basic for `geom_function`
2 parents 94fa7da + a628137 commit e3043ae

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

R/layers2traces.R

+6
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ to_basic <- function(data, prestats_data, layout, params, p, ...) {
173173
UseMethod("to_basic")
174174
}
175175

176+
#' @export
177+
to_basic.GeomFunction <- function (data, prestats_data, layout, params, p, ...) {
178+
data$y <- params$fun(data$x)
179+
prefix_class(data, "GeomPath")
180+
}
181+
176182
#' @export
177183
to_basic.GeomCol <- function(data, prestats_data, layout, params, p, ...) {
178184
prefix_class(data, "GeomBar")
Loading
Loading

tests/testthat/test-ggplot-function.R

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
2+
3+
test_that("ggplotly correctly handles stat_function", {
4+
pl <- p +
5+
stat_function(fun = function(x) x^2+3) +
6+
xlim(1, 5)
7+
8+
expect_doppelganger(ggplotly(pl), "stat-function")
9+
})
10+
11+
test_that("ggplotly correctly handles stat_function", {
12+
pl <- p +
13+
geom_function(fun = function(x) x^2+3) +
14+
stat_function(fun = function(x) 5) +
15+
xlim(1, 5)
16+
17+
expect_doppelganger(ggplotly(pl), "geomfunction")
18+
})

0 commit comments

Comments
 (0)