6
6
# ' @param fun function to use
7
7
# ' @param n number of points to interpolate along
8
8
# ' @param args list of additional arguments to pass to \code{fun}
9
+ # ' @param xlim Optionally, restrict the range of the function to this range.
9
10
# ' @param na.rm If \code{FALSE} (the default), removes missing values with
10
11
# ' a warning. If \code{TRUE} silently removes missing values.
11
12
# ' @inheritParams stat_identity
@@ -51,6 +52,7 @@ stat_function <- function(mapping = NULL, data = NULL,
51
52
geom = " path" , position = " identity" ,
52
53
... ,
53
54
fun ,
55
+ xlim = NULL ,
54
56
n = 101 ,
55
57
args = list (),
56
58
na.rm = FALSE ,
@@ -69,6 +71,7 @@ stat_function <- function(mapping = NULL, data = NULL,
69
71
n = n ,
70
72
args = args ,
71
73
na.rm = na.rm ,
74
+ xlim = xlim ,
72
75
...
73
76
)
74
77
)
@@ -81,8 +84,8 @@ stat_function <- function(mapping = NULL, data = NULL,
81
84
StatFunction <- ggproto(" StatFunction" , Stat ,
82
85
default_aes = aes(y = ..y.. ),
83
86
84
- compute_group = function (data , scales , fun , n = 101 , args = list ()) {
85
- range <- scales $ x $ dimension()
87
+ compute_group = function (data , scales , fun , xlim = NULL , n = 101 , args = list ()) {
88
+ range <- xlim % || % scales $ x $ dimension()
86
89
xseq <- seq(range [1 ], range [2 ], length.out = n )
87
90
88
91
if (scales $ x $ is_discrete()) {
0 commit comments