我注意到,使用scales包,可以在轴上显示美元,例如,使用scales = dollar内部选项scale_y_log10().喜欢的选项scales = euro似乎缺乏.有没有一种简单的方法可以达到同样的效果?
fc9*_*.30 15
你可以使用prefix和的suffix参数dollar_format
例如这样:
library(ggplot2)
library(scales)
ggplot(diamonds) + geom_point(aes(x = carat, y = price)) + scale_y_continuous(labels = dollar_format(suffix = "€", prefix = ""))
Run Code Online (Sandbox Code Playgroud)
Luc*_*zer 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))
}
}
Run Code Online (Sandbox Code Playgroud)