ggplot2:如何为 scale_y_continuous() 设置默认格式化程序?
ggplot2: How to set default formatter for scale_y_continuous()?
我喜欢使用 scale_y_continuous(labels=myformatter)
(使用 myformatter 我的自定义格式化程序函数)作为每个 ggplot 的默认值。
所以我想我可以重新定义函数 scale_y_contiunous
:
scale_y_continuous <- function(...) scale_y_continuous(..., labels=formatter)
但是我得到一个错误
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Error during wrapup: evaluation nested too deeply: infinite recursion / options(expressions=)?
那么有没有办法定义默认行为?
您想在函数中使用 ggplot2
中的 scale_y_continuous
而不是您自己的 scale_y_continuous
。否则你有一个明显的无限递归。您必须使用 ggplot2:::scale_y_continuous
指定它。
scale_y_continuous <- function(...) ggplot2:::scale_y_continuous(..., labels=formatter)
我喜欢使用 scale_y_continuous(labels=myformatter)
(使用 myformatter 我的自定义格式化程序函数)作为每个 ggplot 的默认值。
所以我想我可以重新定义函数 scale_y_contiunous
:
scale_y_continuous <- function(...) scale_y_continuous(..., labels=formatter)
但是我得到一个错误
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Error during wrapup: evaluation nested too deeply: infinite recursion / options(expressions=)?
那么有没有办法定义默认行为?
您想在函数中使用 ggplot2
中的 scale_y_continuous
而不是您自己的 scale_y_continuous
。否则你有一个明显的无限递归。您必须使用 ggplot2:::scale_y_continuous
指定它。
scale_y_continuous <- function(...) ggplot2:::scale_y_continuous(..., labels=formatter)