I want to do sth like in the figure with a Weibull distribution.
But somehow I can't get it to work using stat_function
. I get argument missing
errors. Adding args=list(..)
does not work.
limitRange <- function(fun, min, max) {
function(x) {
y <- fun(x)
y[x < min | x > max] <- NA
return(y)
}
}
ggplot(data.frame(x=c(0,3)), aes(x)) +
stat_function(fun = dweibull,
args = list(shape = 2, scale = 1.12), alpha = .8, size = 1.1) + # works
stat_function(fun = limitRange(dweibull(shape = 2, scale = 1.12), 0.0297, 0.1189),
args = list(shape = 2, scale = 1.12), #doesn't work
geom = "area", fill = "blue", alpha = 0.2)
Any help much appreciated.