ggplot (Zombie, aes(x=Mean_Temp, y=Percent_Infected)) +
   stat_smooth(method="lm", aes (color="Linear")) + 
   stat_smooth(method="loess", aes(color="Loess")) +  
   stat_smooth(method = "nls", formula = y ~ a * log(x) +b,
       aes(color = "logarithmic"),se=F,start = list(a=1,b=1)) + 
   geom_point()
            Asked
            
        
        
            Active
            
        
            Viewed 26 times
        
    -1
            
            
         
    
    
        Ben Bolker
        
- 211,554
- 25
- 370
- 453
- 
                    1What is your question? – markus Nov 22 '20 at 19:57
- 
                    When I run the code the logarithmic line won't show up. And the error says:No starting values specified for some parameters. Initializing ‘a’, ‘b’ to '1.'. Consider specifying 'start' or using a selfStart model – Difei Jiang Nov 22 '20 at 19:58
- 
                    2Consider that nobody knows what `Zombie` is but you. Please read [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – markus Nov 22 '20 at 20:00
1 Answers
3
            
            
        Shortcut: you probably don't need nls(), since y~a*log(x)+b is actually a linear model.  Try method="lm", formula=y~log(x) ...
Guessing here since you haven't shown us a data set, but try method.args= list(start = list(a=1,b=1)). ggplot only knows about a small subset of the possible arguments to a fitting function like nls or lm, everything that's model-specific (like start) needs to be passed through model.args()
Also, try the nls() fit outside of ggplot first to make sure that your starting values work OK/you get sensible results.
 
    
    
        Ben Bolker
        
- 211,554
- 25
- 370
- 453
