I would like to create a ggplot2 plot by faceting geom_function, so that a parameter of the function varies across the grid. e.g. something like this:
my_function<-function(x, par)
{
if(par==1)
{
return(sin(x))
}
else
{
return(cos(x))
}
}
> head(data)
x parameter
1 -1.00 1
2 -0.99 1
3 -0.98 1
4 -0.97 1
5 -0.96 1
6 -0.95 1
> tail(data)
x parameter
397 0.95 2
398 0.96 2
399 0.97 2
400 0.98 2
401 0.99 2
402 1.00 2
> my_plot<-ggplot(data, aes(x)) + geom_function(fun = my_function, args=list(par=parameter)+facet_wrap(~parameter)
which doesn't work because "parameter" is not in scope for the args parameter of geom_function. Is this possible?