rggplot2ggtern

Problem with Error message: could not find function "guides_train"


after updating R I am confronted with the issue, that the message arises "Error: could not find function 'guides_train'.

In fact all ggplot diagrams work - only if I do a ternary plot, using the package ggtern, then all diagrams I prepared before don't work any more.

I have also tried to use standard example codes still there I get the same error.

https://www.r-bloggers.com/2017/07/version-2-2-1-released/

library(ggtern)
library(ggalt)     #<<< Install this if it isn't installed!
data("Fragments")
base = ggtern(Fragments,aes(Qm,Qp,Rf+M,fill=GrainSize,shape=GrainSize)) + 
  theme_bw() + 
  theme_legend_position('tr') + 
  geom_encircle(alpha=0.5,size=1) + 
  geom_point() +
  labs(title    = "Example Plot",
       subtitle = "using geom_encircle")
print(base)

I figured out that "guides_train" is changed in the current ggplot2 Version 3.5.0, https://ggplot2.tidyverse.org/news/index.html. When I look at the download data of the latest ggtern version, https://cran.r-project.org/web/packages/ggtern/index.html, it refers to ggplot2 ≥ 3.4.0.

I am not sure then if changes with ggplot2 3.5.0 are really considered, and I don't know if I had to consider anything else. I have tried to install older ggplot2, but without success.

I am very grateful for hints.


Solution

  • R is not the culprit. In R 4.3.2, I tried to run the code. Before updating ggplot2, it worked (version 3.4.4). After installing the newest version of ggplot2 (3.5.0), I got the same error message as you did. Your suspicion is correct, the ggplot2 update broke the functionality of guide_train(), and ggtern devs have not had enough time to adress this. Maybe your best option is to revert back to ggplot2 3.4.4.. To do this, unload ggplot2 if it currently loaded. For example by restarting R. Then:

    require(devtools)
    install_version("ggplot2", version = "3.4.4", repos = "http://cran.us.r-project.org")
    

    Usually, I would also recommend filing a bug report at ggterns website, so devs get notified of the problem. But their website is unavailable unfortunately.

    Another fix involves fixing the source code of ggtern yourself, to accept the remodeled guide system of ggplot2 3.5.0.