У меня есть функция, которую я создаю так:
library(ggplot2)
plot_function <- function(data, x, y){
ggplot(data, aes_string(x=x, y=y)) +
geom_line() +
scale_y_continuous(labels = scales::comma_format())
}
Я могу назвать это так:
df <- data.frame(date = seq(as.Date("2019/01/01"), as.Date("2019/01/05"),"1 day"),
value = seq(.1,.5, .1))
df
date value
2019-01-01 0.1
2019-01-02 0.2
2019-01-03 0.3
2019-01-04 0.4
2019-01-05 0.5
plot_function(df, x = "date", "value")

Но что, если бы я хотел позволить пользователю иметь возможность изменять ось Y в процентах. Как я могу позволить им заменить scales::comma_format()
? Это не работает:
plot_function <- function(data, x, y, y_format){
ggplot(data, aes_string(x=x, y=y)) +
geom_line() +
scale_y_continuous(labels = y_format)
}
plot_function(df, x = "date", "value", y_format = "scales::percent_format()")
Я получаю эту ошибку:
"Error in f(..., self = self) : Breaks and labels are different lengths"