我注意到,使用scales
包,可以使用内部的scales = dollar
选项在轴上显示美元,例如scale_y_log10()
。像scales = euro
这样的选项似乎缺乏。有没有一种简单的方法可以达到同样的效果?ggplot中的欧元符号:秤包
5
A
回答
12
很容易修改dollar_format并将符号更改为欧元。运行这个并把它放在这样的代码,你会打电话dollar_format
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))
}
}
6
您可以使用dollar_format
的prefix
和suffix
参数例如像这样:
library(ggplot2)
library(scales)
ggplot(diamonds) + geom_point(aes(x = carat, y = price)) + scale_y_continuous(labels = dollar_format(suffix = "€", prefix = ""))
相关问题
- 1. 欧元符号
- 2. 茉莉SMPP欧元符号
- 3. 回声欧元符号
- 4. imagettftext和欧元符号
- 5. 欧元符号转换为问号
- 6. 正则表达式的欧元符号(€)
- 7. 欧元符号越狱输出:?€
- 8. MySQL ::连接器/净欧元符号
- 9. 用pgf/tikz创建欧元符号
- 10. 欧元符号JNA皈依问题
- 11. 在闪亮的R应用程序中显示欧元符号
- 12. EuroCRM账户中的欧元/货币符号
- 13. 我如何使用逗号和欧元符号
- 14. ggplot facet strip text中的符号
- 15. 欧元符号不能正确显示在HTML中
- 16. 如何把欧元符号放在html R plotly图中?
- 17. FlyingSaucer(xhtmlrenderer):在PDF中呈现€(欧元)符号
- 18. 无法在“C”程序中打印欧元符号
- 19. 如何将欧元符号存储在mysql数据库中?
- 20. 如何在C中生成欧元符号?
- 21. 编码 - 显示欧元符号和更多 - UTF-8字符集
- 22. 检查字符串是否以欧元/英镑符号开头
- 23. oracle欧元字符问题
- 24. 特殊字符欧元
- 25. Oracle JDBC欧元字符
- 26. 在表单中提交欧元符号并获取额外的2个字符
- 27. 奇怪的现象:Java转义欧元符号
- 28. 嵌入支持欧元符号的字体
- 29. 不能欧元货币转换成它的符号
- 30. php json_encode适用于Android的欧元符号
非常感谢,这工作正常!对于那些仍然感到困惑的人来说,除了'ggplot'和'scales'之外,您还需要加载'reshape'和'stringr'包来完成这个工作。 – 2012-08-14 06:29:25
在有限的测试中,我发现以下工作,它只依赖于''ggplot2''和'''':''euroFrance < - function(x)paste0(format(x,big.mark =“ “,decimal.mark =”,“,trim = TRUE, scientific = FALSE),”€“)}''(我选择了法国风格与Luciano的例子进行对比,并展示了可能性的范围)。或者换句话说,如果你不需要担心舍入或修整小数点,一个简单的函数就可以做到。哦,你会这样称呼它:''+ scale_y_continuous(labels = euroFrance,breaks = etc.'' – PatrickT 2014-12-20 18:08:27