JerryWho
JerryWho

Reputation: 3105

ggplot2: How to set default formatter for scale_y_continuous()?

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?

Upvotes: 1

Views: 573

Answers (1)

shadow
shadow

Reputation: 22333

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)

Upvotes: 2

Related Questions