5

I am trying to add a geom_smooth() to a qplot() with the following code:

library(ggplot2)
library(ggplot2movies)
qplot(votes, rating, data = movies) + geom_smooth()

However, the smoother is missing from the plot. I also receive the following warning message:

Computation failed in stat_smooth(): object 'C_crspl' not found

Does anybody know what is wrong here?

This is my setup:

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS
Samuel
  • 2,895
  • 4
  • 30
  • 45
  • It would be great if you could provide a sample dataset to illustrate the issue that you are encountering. Refer to: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Curious T Aug 11 '17 at 18:09
  • The sample dataset is `movies` from the library `ggplot2movies`. – Samuel Aug 11 '17 at 18:10
  • The above code works without any issues. What if you try the following: `qplot(votes, rating, data = movies, geom = c("point", "smooth"))` – Curious T Aug 11 '17 at 18:22

4 Answers4

5

I had similar issues:

# `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
# Warning message:
# Computation failed in `stat_smooth()`:
# object 'C_crspl' not found 

and

# Warning message:
# Computation failed in `stat_smooth()`:
# object 'C_magic' not found  

when using geom_smooth(method="gam"). The problems vanished when I explicitly loaded the mgcv package version 1.8-17. I guess by default, ggplot (I use 2.2.1.9000) looked at 1.8-16, which was also in the search path. So you might want to update mgcv or make sure that the latest version is used.

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • 1
    I was really hoping that this was the underlying cause, because I was facing this issue while using a GAM smooth, but this does not appear to solve the issue, at least for me. – tchakravarty Nov 18 '17 at 19:21
2

I could not reproduce your problem: it works fine in my system. I guess you have a problem with some ggplot2 dependency. Try restarting your session and reinstall ggplot2.

If that doesn't work, test geom_smooth() with a different dataset and a different method, e.g. qplot(Sepal.Length, Sepal.Width, data = iris) + geom_smooth(method = 'lm')

PeerEZ
  • 231
  • 1
  • 2
  • 8
1

I had the same exact issue. Tried loading mgcv explicitly and this did nothing. Since I originally relied on ggplot2 to install mgcv, I went back and installed mgcv myself so that the newest version was included and then re-installed ggplot2 and the issue went away. This is on Ubuntu 16.04 with ggplot2 2_2.2.1 and mgcv 1.8-23.

ZRoss
  • 1,437
  • 1
  • 15
  • 32
0

I also had this problem and almost gave up. However, when I simply reinstalled mgcv before and ggplot2 later, the script simply went back to working as before.