Incompatible methods ("Ops.S7_object", "+.gg") for "+

Hi everyone!

I've been working on some project using Shiny to develop a workflow for data processing. After coming back to work after Christmas holidays, the code has stopped working because of the error displayed at the tile, being unable to use "+" for ggplot.

Here you are a minimum example of that. I've already seen a similar topic but would appreciate if there would be any way to correct the issue without having to revert to a previous version of ggplot2.

library(ggplot2)
data<-as.data.frame(matrix(runif(20, 0, 5), nrow=4), metadata=c(1,2,2,1))

gg_plot<<-ggplot(data=data, aes(x=metadata, y=V1))+
  geom_violin(show.legend=F, trim=F)

Thanks!

When I ran your code, I got an error about metadata not being found and indeed that's not being added to your data correctly. This runs fine for me though with ggplot2 v4.0.1:

library(ggplot2)
data<-as.data.frame(matrix(runif(20, 0, 5), nrow=4))
data$metadata <- c(1,2,2,1)
ggplot(data=data, aes(x=metadata, y=V1)) +
  geom_violin(show.legend=F, trim=F)

I'm not much of a ggploter, but it is definitely still okay to use +. Maybe this isn't an equivalent example to the problem you're experiencing?

I tried redownloading the package to have the newest version installed, trying to check if it was an installation error, but after restarting R the error came back.

Error in ggplot(data = data, aes(x = metadata, y = V1)) + geom_violin(show.legend = F,  : 
  argumento no-numérico para operador binario
Además: Warning message:
Métodos incompatibles ("Ops.S7_object", "+.gg") para "+" 

Hmm. That's strange. I'm not sure I can help you, but it would be worth providing the output of sessionInfo() in case that gives clues to someone else. If no one here can help, probably best to open an issue on github.

Here is everything that comes out after replicating the error:

R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 26100)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Spain.utf8  LC_CTYPE=Spanish_Spain.utf8    LC_MONETARY=Spanish_Spain.utf8
[4] LC_NUMERIC=C                   LC_TIME=Spanish_Spain.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_4.0.0

loaded via a namespace (and not attached):
 [1] Biobase_2.58.0       viridis_0.6.5        tidyr_1.3.1          viridisLite_0.4.2    splines_4.2.1       
 [6] ellipse_0.5.0        RcppParallel_5.1.7   S7_0.2.1             Rdpack_2.6.4         stats4_4.2.1        
[11] impute_1.72.3        norm_1.0-11.1        ggrepel_0.9.5        factoextra_1.0.7     tmvtnorm_1.7        
[16] pillar_1.11.1        lattice_0.20-45      limma_3.54.2         glue_1.8.0           digest_0.6.39       
[21] RColorBrewer_1.1-3   rbibutils_2.2.16     randomForest_4.7-1.2 stringfish_0.16.0    sandwich_3.1-1      
[26] htmltools_0.5.9      Matrix_1.4-1         plyr_1.8.9           pkgconfig_2.0.3      pheatmap_1.0.13     
[31] purrr_1.2.0          mvtnorm_1.2-4        scales_1.4.0         ggstats_0.11.0       RApiSerialize_0.1.4 
[36] gmm_1.9-1            tibble_3.3.0         missRanger_2.6.1     mgcv_1.9-3           generics_0.1.4      
[41] farver_2.1.2         DT_0.34.0            withr_3.0.2          imputeLCMD_2.1       BiocGenerics_0.44.0 
[46] cli_3.6.5            magrittr_2.0.4       Kendall_2.2.1        RFPM_1.1             GGally_2.2.1        
[51] nlme_3.1-157         MASS_7.3-57          vegan_2.6-4          Cairo_1.6-2          data.table_1.17.8   
[56] tools_4.2.1          lifecycle_1.0.4      stringr_1.6.0        cluster_2.1.3        plotrix_3.8-13      
[61] pls_2.8-5            pcaMethods_1.90.0    compiler_4.2.1       qs_0.26.1            rlang_1.1.6         
[66] grid_4.2.1           rstudioapi_0.17.1    rjson_0.2.23         htmlwidgets_1.6.4    lawstat_3.6         
[71] boot_1.3-28          gtable_0.3.6         R6_2.6.1             gridExtra_2.3        zoo_1.8-12          
[76] dplyr_1.1.4          fastmap_1.2.0        permute_0.9-8        stringi_1.8.7        parallel_4.2.1      
[81] Rcpp_1.0.10          vctrs_0.6.5          tidyselect_1.2.1

You have quite a few ggplot-related packages loaded and I don't think all of those are up to date. E.g. a semi-random pick, GGally_2.2.1 (CRAN release 2024-02-13), while you need at least 2.3 for ggplot2_4.0.0:

GGally 2.3.0

CRAN release: 2025-07-18

  • With ggplot2 v4.0.0, objects are now +’ed together using S7. This means the startup message for Registered S3 method overwritten by 'GGally' has been removed. (Thank you @teunbrand for the enhancement in ggplot2! #545)
  • Prepare GGally for ggplot2 v4 (Thank you @teunbrand! #528)

[ Changelog • GGally ]

Oh, thanks!
I haven't thought of updating R as it didn't say that I needed new versions of packages. Now it works as smoothly as ever.