Need help with error when running "geom_smooth()` using formula 'y ~ x'"

I am pretty new to R. I am trying to run a dataset with the following code:

ggplot(RW, aes(y=Caught, x=Stocked))+

  • geom_point()+
  • geom_smooth(method = lm)

I keep getting an error that says "geom_smooth() using formula 'y ~ x'"

Also, the graph isn't showing some points because the x and y values are out of the range. I want them to go from 0 to 140,000. Instead the y-axis goes from 118,708 to 73473.66 and the x-axis goes from 140,522 to 59613 I have tried a couple different ways but keep getting another error, which is "Error: Discrete value supplied to continuous scale"

What do I need to do? Thanks!

The warning

geom_smooth() using formula 'y ~ x'

is not an error. Since you did not supply a formula for the fit, geom_smooth assumed y ~ x, which is just a linear relationship between x and y. You can avoid this warning by using

geom_smooth(formula = y ~ x, method = "lm")

The axis behavior you describe and the error about discrete values suggests that non-numeric values, i.e. text, are being passed to a function. Can you post the code you use to set the axis limits? It would also be useful to see the output of


Place lines containing only three back ticks, ```, just before and just after the output.
paste the output here

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.