1

I like to use scale_y_continuous(labels=myformatter) (with myformatter my custom formatter-function) as default for every ggplot.

So I thought I could redefine the function scale_y_contiunous:

scale_y_continuous <- function(...) scale_y_continuous(..., labels=formatter)

But I get an error

Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Error during wrapup: evaluation nested too deeply: infinite recursion / options(expressions=)?

So is there a way to define the default behaviour?

JerryWho
  • 3,060
  • 6
  • 27
  • 49
  • You could write your own theme for this... Even make it default. – Roman Luštrik Jan 16 '15 at 10:02
  • @RomanLuštrik Okay, but how do I define the default behaviour for the axis? I found `update_geom_defaults`. But this seems not to set the axis. – JerryWho Jan 16 '15 at 10:07
  • It would seem I was a bit hasty with the theme comment. It doesn't change the geom default values - as you've already found out, `update_geom_defaults` should do that. What is the command you're using that doesn't work? – Roman Luštrik Jan 16 '15 at 10:16
  • @RomanLuštrik I haven't used any command as I think `update_geom_defaults` is the wrong command. But the @shadow's answer works for me. – JerryWho Jan 16 '15 at 10:50
  • related https://stackoverflow.com/questions/9944246/setting-defaults-for-geoms-and-scales-ggplot2 – tjebo Aug 24 '23 at 16:59

1 Answers1

2

You want to use the scale_y_continuous from ggplot2 inside your function instead of your own scale_y_continuous. Otherwise you have an obvious infinite recursion. You have to specify this using ggplot2:::scale_y_continuous.

scale_y_continuous <- function(...) ggplot2:::scale_y_continuous(..., labels=formatter)
shadow
  • 21,823
  • 4
  • 63
  • 77