I am creating a function that automatically plots a number of curves based on user input. However, when I loop through the ggplot, all the plots look the same when they should be different. My data looks something like this:
PseudoA | PseudoB |
---|---|
0.546 | 0.646 |
0.234 | -0.757 |
... | ... |
Let's imagine the user wants to plot 5 curves, I tried using the following loop:
p<-list()
for(i in 1:5){
eq<-function(x){c + ((1-c)*(1/(1+2.71828^(-1.7*(df$PseudoA[i]*(x-df$PseudoB[i]))))))}
p[[i]]<-ggplot()+geom_function(fun=eq)+
scale_x_continuous(limits=c(-4,4),breaks=waiver(), labels=c("0.9","0.7","0.5","0.3","0.1"))
}
library(gridExtra)
grid.arrange(grobs=c(p[1:5]), ncol=2, rnow=3)
But it plots the same curve five times, as you can see here, even though when I plot them separately outside of the loop they're all very different:
Keep in mind that I don't know how many plots the user is going to want, whether 5, 10 or 20, hence the loop. Any help would be appreciated!