我注意到,通过使用scales包,可以使用内部的scales = dollar选项(例如scale_y_log10() )在轴上显示美元。像scales = euro这样的选择似乎是缺乏的。有没有简单的方法让我达到同样的效果?
发布于 2012-08-14 01:14:33
可以很容易地修改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))
}
}发布于 2015-08-28 15:01:19
您可以使用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 = ""))https://stackoverflow.com/questions/11935797
复制相似问题