Я изучаю R. С помощью Maximilian Peters' answer я написал пользовательскую функцию, чтобы сделать кучу заговорных карт рассеяния. Я хочу пометить заголовки оси x и y именами столбцов из этих переменных.Заголовок xaxis в пользовательской функции с использованием R plot_ly
Вот код:
library(plotly)
my_plot <- function(x, y, ...) {
plot_ly(y = y, x = x, ...) %>%
add_markers() %>%
layout(xaxis = list(title = deparse(substitute(x))),
yaxis = list(title = deparse(substitute(y))))
}
my_plot(y = mtcars$mpg, x = mtcars$disp)
Устанавливает заголовок XAxis на «х», но я хочу, чтобы это было «СМЕЩЕНИЕ».
Я также попробовал этот код:
my_plot <- function(data, x, y, ...) {
plot_ly(y = data[[y]], x = data[[x]], ...) %>%
add_markers() %>%
layout(xaxis = list(title = deparse(substitute(data[[x]]))),
yaxis = list(title = deparse(substitute(data[[y]]))))
}
my_plot(data = mtcars, y = 'mpg', x = 'disp')
Это устанавливает заголовок XAxis к "данным [[х]]".