0

I am using this:

library(datasets)
library(ggplot2)

model <- gam(
    Petal.Width ~

    s(Sepal.Length)

    , data = iris
    , method = "REML"
)

ggplot(iris, aes(x = Petal.Width, y = Sepal.Length)) +
geom_point() +
geom_smooth(method = "gam", formula = Petal.Width ~ s(Sepal.Length))

but get this error:

Warning message:
Computation failed in `stat_smooth()`:
object 'Petal.Width' not found 

any ideas? Thanks!

cs0815
  • 16,751
  • 45
  • 136
  • 299
  • Seems to be the same problem as: https://stackoverflow.com/questions/45640913/computation-failed-in-stat-smooth-object-c-crspl-not-found – RLave Nov 27 '18 at 14:04
  • 1
    Two things: your `gam` models x&y are in a different order from your plot. Within the `geom_smooth` call don't use the variable names, use `formula = y ~ s(x)` (also `mgcv::gam` has a plot method, so you can get a simple plot using `plot(model, shade=1, scale=0, residuals = TRUE, cex=4)` but is obviously useful as more smooths are added to the model ) – user20650 Nov 27 '18 at 18:32
  • @user20650 - using formula = y ~ s(x) solves it - thanks! Please post answer. – cs0815 Nov 27 '18 at 20:42

0 Answers0