Say we have this toy data:
temp <- data.frame(A=1:6, gr=c("A","A","A","B","B","B"))
I can easily create a plot as
lev <- c("A", "B")
ggplot()+geom_point(data=temp,aes(x=A, y=gr))+ylim(lev)
But I would like to convert it to a function in order to easily change the input parameters
myplot <- function(lev=lev) {ggplot()+geom_point(data=temp,aes(x=A, y=gr))+ylim(lev)}
But when I run
lev <- c("B","A")
myplot()
I get this error:
Error in limits(c(...), "y") : promise already under evaluation: recursive default argument reference or earlier problems?
I've tried converting ylim to a factor, and using eval, but it doesn't work either.
I've tried parametrizing other things such as the input dataset and they work well, but I don't understand why ylim doesn't.
There is a question that speaks about a related problem with aes parameters
Pass function argument to ggplot label
but its solution uses aes_string and doesn't apply here.