(reprex enclosed) Save base R plots coordinates / modify text on plot created by function.

Hi,

REPREX ENCLOSED!

I guess my problem is general to those who write academic paper on native language. I would like to change the text on a plot created by a specific function. But unlike gg plots I can not find how to reach the coordinates or to modify the text already printed on the plot. If I add a new title it just prints 2 titles. So I would like to change axis legend and main title on the plot (better if I can save out the points and recreate it with gg).

Thanks for your answer in advance,
M

library(earth)
#> Loading required package: Formula
#> Loading required package: plotmo
#> Loading required package: plotrix
#> Loading required package: TeachingDemos
fit <- earth(Sepal.Length ~ ., data = iris)

earth_plotmodsel(fit)

Created on 2022-03-26 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.1.2 (2021-11-01)
#>  os       macOS Monterey 12.2.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  hu_HU.UTF-8
#>  ctype    hu_HU.UTF-8
#>  tz       Europe/Budapest
#>  date     2022-03-26
#>  pandoc   2.17.1.1 @ /usr/local/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package       * version date (UTC) lib source
#>  cli             3.2.0   2022-02-14 [2] CRAN (R 4.1.1)
#>  curl            4.3.2   2021-06-23 [2] CRAN (R 4.1.0)
#>  digest          0.6.29  2021-12-01 [2] CRAN (R 4.1.1)
#>  earth         * 5.3.1   2021-07-20 [2] CRAN (R 4.1.0)
#>  evaluate        0.15    2022-02-18 [2] CRAN (R 4.1.1)
#>  fastmap         1.1.0   2021-01-25 [2] CRAN (R 4.1.0)
#>  Formula       * 1.2-4   2020-10-16 [2] CRAN (R 4.1.0)
#>  fs              1.5.2   2021-12-08 [2] CRAN (R 4.1.1)
#>  glue            1.6.2   2022-02-24 [2] CRAN (R 4.1.1)
#>  highr           0.9     2021-04-16 [2] CRAN (R 4.1.0)
#>  htmltools       0.5.2   2021-08-25 [2] CRAN (R 4.1.1)
#>  httr            1.4.2   2020-07-20 [2] CRAN (R 4.1.0)
#>  knitr           1.38    2022-03-25 [2] CRAN (R 4.1.1)
#>  magrittr        2.0.2   2022-01-26 [2] CRAN (R 4.1.1)
#>  mime            0.12    2021-09-28 [2] CRAN (R 4.1.1)
#>  plotmo        * 3.6.1   2021-07-17 [2] CRAN (R 4.1.0)
#>  plotrix       * 3.8-2   2021-09-08 [2] CRAN (R 4.1.1)
#>  R6              2.5.1   2021-08-19 [2] CRAN (R 4.1.1)
#>  reprex          2.0.1   2021-08-05 [1] CRAN (R 4.1.1)
#>  rlang           1.0.2   2022-03-04 [2] CRAN (R 4.1.1)
#>  rmarkdown       2.13    2022-03-10 [2] CRAN (R 4.1.1)
#>  rstudioapi      0.13    2020-11-12 [2] CRAN (R 4.1.0)
#>  sessioninfo     1.2.2   2021-12-06 [2] CRAN (R 4.1.1)
#>  stringi         1.7.6   2021-11-29 [2] CRAN (R 4.1.1)
#>  stringr         1.4.0   2019-02-10 [2] CRAN (R 4.1.1)
#>  TeachingDemos * 2.12    2020-04-07 [2] CRAN (R 4.1.0)
#>  withr           2.5.0   2022-03-03 [2] CRAN (R 4.1.1)
#>  xfun            0.30    2022-03-02 [2] CRAN (R 4.1.1)
#>  xml2            1.3.3   2021-11-30 [2] CRAN (R 4.1.1)
#>  yaml            2.3.5   2022-02-21 [2] CRAN (R 4.1.1)
#> 
#>  [1] /Users/marci/Library/R/arm64/4.1/library
#>  [2] /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Hi @Marcell,
The earth() output object (list) is pretty complicated so its tough to pull out all the required components for plotting with ggplot2(). See str(fit).

One option is to edit the plotting function and replace the English text strings (title, legend, etc.) with your language, and giving it a new name e.g. earth_plotmodsel_french().
Use View(earth_plotmodsel) to see the original function code and what's involved in such an edit.

Hope this helps.

I also thought about these solutions, but looking the earth object did not help. And the ploting function contains internal functions dota which prevents me being able to copy and paste the lines of the function and create a new one. So none of these tips could work for me, but thank you for the answer.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.