You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
geom_smooth doesn't work when function is entered with :: #2870
# loading needed libraries
library(ggplot2)
library(mgcv)
#> Loading required package: nlme
#> This is mgcv 1.8-24. For overview type 'help("mgcv-package")'.
# without `::`
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
geom_smooth(method = "gam", formula = y ~ s(x, k = 3))
# with `::`
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
geom_smooth(method = "gam", formula = y ~ mgcv::s(x, k = 3))
#> Warning: Computation failed in `stat_smooth()`:
#> invalid type (list) for variable 'mgcv::s(x, k = 3)'
# this indeed a function from `mgcv package`
args(mgcv::s)
#> function (..., k = -1, fx = FALSE, bs = "tp", m = NA, by = NA,
#> xt = NULL, id = NULL, sp = NULL, pc = NULL)
#> NULL
Created on 2018-08-28 by the reprex package (v0.2.0.9000).
This is an mgcv bug. If you try to fit a gam model outside of ggplot2 you'll see that you'll get the same error. See #2621 for a prior discussion on this issue.
library(mgcv)
#> Loading required package: nlme#> This is mgcv 1.8-24. For overview type 'help("mgcv-package")'.x<- rnorm(50)
y<-x^2+0.3*rnorm(50)
df<-data.frame(x, y)
gam(y~ s(x), data=df)
#> #> Family: gaussian #> Link function: identity #> #> Formula:#> y ~ s(x)#> #> Estimated degrees of freedom:#> 5.22 total = 6.22 #> #> GCV score: 0.05352554
gam(y~mgcv::s(x), data=df)
#> Error in model.frame.default(formula = y ~ mgcv::s(x), data = df, drop.unused.levels = TRUE): invalid type (list) for variable 'mgcv::s(x)'
Activity
clauswilke commentedon Aug 29, 2018
This is an mgcv bug. If you try to fit a gam model outside of ggplot2 you'll see that you'll get the same error. See #2621 for a prior discussion on this issue.
Created on 2018-08-28 by the reprex package (v0.2.0).
lock commentedon Feb 25, 2019
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/