我注意到,使用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. 回声欧元符号
- 3. 不显示欧元符号
- 4. 欧元符号编码 - PHP
- 5. 茉莉SMPP欧元符号
- 6. imagettftext和欧元符号
- 7. php preg_replace欧元符号
- 8. 欧元符号转换为问号
- 9. 在ggplot2中绘制欧元符号€?
- 10. 正则表达式的欧元符号(€)
- 11. 欧元符号的编码问题
- 12. 通过颠覆提交€欧元符号
- 13. 欧元符号越狱输出:?€
- 14. 用JSTL显示欧元符号
- 15. 用pgf/tikz创建欧元符号
- 16. FPDF calibri不显示欧元符号
- 17. MySQL ::连接器/净欧元符号
- 18. 如何写欧元(€)符号到Android PDF
- 19. jQuery不识别欧元符号
- 20. Zend_Pdf:欧元符号不显示
- 21. 欧元符号JNA皈依问题
- 22. rawurldecode不解码欧元符号
- 23. 将欧元和美元符号插入到mysql的列中
- 24. 将美元更改为键盘布局中的欧元符号
- 25. 在Python中使用xml.etree编写包含欧元符号(€)的xml文件
- 26. 从字符串中删除欧元符号
- 27. IBM UDB .Net中使用欧元符号(€)的转换错误
- 28. 欧元符号不会显示在dompdf生成的pdf中
- 29. EuroCRM账户中的欧元/货币符号
- 30. 在闪亮的R应用程序中显示欧元符号
非常感谢,这工作正常!对于那些仍然感到困惑的人来说,除了'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