ggplot2:如何设置scale_y_continuous()的默认格式化程序? [英] ggplot2: How to set default formatter for scale_y_continuous()?

查看:1698
本文介绍了ggplot2:如何设置scale_y_continuous()的默认格式化程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢使用 scale_y_continuous(labels = myformatter)(使用myformatter我的自定义格式化函数)作为每个ggplot的默认值。



所以我想我可以重新定义函数 scale_y_contiunous

  scale_y_continuous < - 函数(...)scale_y_continuous(...,labels = formatter)

但是我得到一个错误

 错误:评估嵌套得太深了:无限递归/选项(表达式=)? 
在包装过程中出现错误:评估嵌套过深:无限递归/选项(表达式=)?

那么是否有一种方法可以定义默认行为?

ggplot2 里面使用 scale_y_continuous 你的函数,而不是你自己的 scale_y_continuous 。否则,你有一个明显的无限递归。你必须使用 ggplot2 ::: scale_y_continuous 来指定。

  scale_y_continuous < - 函数(...)ggplot2 ::: scale_y_continuous(...,labels = formatter)


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?

解决方案

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)

这篇关于ggplot2:如何设置scale_y_continuous()的默认格式化程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆