What's wrong with my code? Why am I getting such a weird graph? Also, is there a better way to graph the model? I feel that my code is not the best, by some reason.
Glad to help. If you think your question was answered, can you mark it as such so that the question is shown as answered?
The logic behind the formula/data syntax is that the variables are defined in a context -- the data frame -- in the formula syntax while they are defined in a fashion that can't be separated from their context in something like df$x. This then induces a problem when we try to replace them to predict because R really only knows to look for df$x as a pair rather than a variable name in whatever new context we supply in the newdata= argument to predict. That said, I learned this because a student tried it, it failed, and they asked why. I don't know of a reference for it.