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

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

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.

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')

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.

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.

Related

Error when running MCP library - 'rlang_is_formula'

I'm trying to run a model with the mcp package. Here is what I'm running:
model <- list(
response ~ 1,
~ 0 + time,
~ 0 + time)
fit <- mcp(model, data=df)
This gives the error: Error in is.type(x) : object 'rlang_is_formula' not found
I've tried removing and reinstalling the rlang package, with no luck. I'm using R-4.1.2, and rlang is version 1.0.4. mcp package is version 0.3.1.
Any ideas how to solve this issue?
Detaching other problematic packages and reloading everything did not work. The issue was resolved after reinstalling the mcp package completely.

Issue installing packages "labeling" and "scales" in RStudio 2022.02.3

I usually plot my data with the following ggplot syntax:
ggplot(sent.TN.yr.avg, aes(y = (log10(mean)), x = YEAR, color = ECOREGION)) +
geom_point(size = 1, alpha = 0.4) +
geom_smooth(se=TRUE) +
xlab(expression(paste("Year"))) + ylab(expression(paste("Mean TN (", mu, "g", L^-1,")"))) +
theme_light()
But this recently led me to the following loadnamespace(name) error:
Error in loadNamespace(x) : there is no package called ‘labeling’
I'm not sure how this code prompted an error related to "labeling." Still, I tried restarting RStudio and installing that, but it cannot be supported by this version of RStudio (2022.02.3). I also tried the same thing with the "scales" package and got the same result. I've also tried changing the repository to different CRAN mirrors with no success.
Any tips?
Package ggplot2 imports package scales which imports package labeling. So in order to use ggplot you should have installed the other two packages as well.
The version of RStudio most likely has nothing to do with it. But if you recently switched from R version 4.1.* to R4.2.* you have to upgrad all your installed packages (they have to be recompiled after a major R version release).
You can do this in RStudio: Tools -> Check for Package Updates...
or directly in R with: update.packages(checkBuilt = TRUE)
By the way, on the ggplot2 page there is an example of how mathematical expressions can be inserted into axis labels:
https://ggplot2.tidyverse.org/articles/faq-axes.html?q=superscript#how-can-i-add-superscripts-and-subscripts-to-axis-labels

Color error in ggplot2 (Error in grDevices::col2rgb(colour, TRUE) : invalid RGB specification)

If I run:
library(ggplot2)
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
bp<-ggplot(ToothGrowth, aes(x=dose, y=len, fill=dose)) +
geom_boxplot()
bp
I see the error: Error in grDevices::col2rgb(colour, TRUE) : invalid RGB specification.
If I run the identical code on my other computer, I get the expected plot. I am guessing that some plotting parameter is the culprit, but I have no idea how to find it. What's going wrong?
The computer that behaves strangely is Mac OS X 10_11_3 running R 3.2.2 via RStudio 0.99.489
Sorry I am late, but the problem is that the function alpha is masked form ggplot2, that's why if you restart R and happen to call alpha after sourcing psych but before ggplot2 it works.
Anyway, the way to solve it is to make explicit that we want the psych function:
reliability = psych::alpha(df)
Restarting R was sufficient to fix the weird behavior. Obviously should have tried that before posting...

Error in clusplot function

I am playing with cluster analysis in R and I would like to plot the cluster:
teste<-data.frame(v1=rnorm(100),v2=rexp(100),v3=runif(100) )
fit.c<- kmeans(teste,2)
aggregate(teste,by=list(fit.c$cluster),FUN=mean)
clusplot(teste, fit.c$cluster, color=TRUE, shade=TRUE,labels=2, lines=0)
But it gives me this error:
Error in clusplot.default(teste, fit.c$cluster, color = TRUE, shade = TRUE, :
4 arguments passed to .Internal(nchar) which requires 3
Does anyone know what is happening?
Thank you
I ran your code and got no problems. I am guessing that there is a version mismatch between your R and the packages you are using. Can you make sure that your cluster package is up to date (and any other packages you are using for that matter), and/or update to the latest version of R?
If that doesn't work, can you add the sessionInfo() information? That is often helpful for diagnosing these sorts of problems.

RStudio-only error with tcl/tk?

When I compute an ROC plot with the package pROC, I get the following error in RStudio v. 99.9.9:
## Loading required package: tcltk
## Warning: couldn't connect to display ":0"
## Error: [tcl] invalid command name "toplevel".
I thought this was an issue in my OS (Debian with r-base 3.1 installed from APT depending on tcl/tk lib version 8.5), but when evaluating the same code through the terminal, I get the plot rendered without the same error.
Here is a simple example following some pROC example code that will generate the error when knitted in RStudio, but works in vanilla R:
```{r markdown.test}
library(pROC)
features <- runif(25)
labels <- as.factor(runif(25) < 0.75)
lda.model <- lda(as.matrix(features),labels)
lda.pred <- predict(lda.model,as.matrix(features))
lda.roc <- plot.roc(lda.pred$posterior[,1],
c(labels),
ci=TRUE, of="se", #specificities = seq(0,100,5),
ci.type="shape",
ci.col="#1c61b6AA")
```
The error occurs when the confidence interval parameters are added to the call.
Is there something missing from my RStudio install/config, or is this a bug?
Blast from the past! I see that same error today on an instance of RStudio installed in the IBM computing environment called CP4D. Did you ever find an answer?
I think the way to fix on your Macintosh is to install Quartz and let it serve as the X11 server to display output from programs like tcltk or maybe even hist() or quartz() devices. (my team wrote install instructions https://pj.freefaculty.org/guides/crmda_guides/47.mac_R_setup).
I'm not sure what I'll do on the CP4D thing, since it is running inside a Web browser.

Resources