首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Euro-登录ggplot: scale包

Euro-登录ggplot: scale包
EN

Stack Overflow用户
提问于 2012-08-13 21:57:12
回答 2查看 7.2K关注 0票数 8

我注意到,通过使用scales包,可以使用内部的scales = dollar选项(例如scale_y_log10() )在轴上显示美元。像scales = euro这样的选择似乎是缺乏的。有没有简单的方法让我达到同样的效果?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-14 01:14:33

可以很容易地修改dollar_format并将符号更改为欧元。运行此代码并将其放入代码中,就像调用dollar_format一样

代码语言:javascript
复制
euro_format <- function(largest_with_cents = 100000) {
  function(x) {
    x <- round_any(x, 0.01)
    if (max(x, na.rm = TRUE) < largest_with_cents &
        !all(x == floor(x), na.rm = TRUE)) {
      nsmall <- 2L
    } else {
      x <- round_any(x, 1)
      nsmall <- 0L
    }
    str_c("€", format(x, nsmall = nsmall, trim = TRUE, big.mark = ",", scientific = FALSE, digits=1L))
  }
}
票数 12
EN

Stack Overflow用户

发布于 2015-08-28 15:01:19

您可以使用dollar_formatprefixsuffix参数

例如:

代码语言:javascript
复制
library(ggplot2)
library(scales)       
ggplot(diamonds) + geom_point(aes(x = carat, y =  price)) + 
   scale_y_continuous(labels = dollar_format(suffix = "€", prefix = ""))
票数 22
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11935797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档