Attempt of a function:
plot_eval <- function(data, metric) {
data |>
ggplot(aes(x = cut, y = metric)) +
geom_point() +
ggtitle(metric)
}
Tried with diamonds data set e.g:
plot_eval(diamonds, price)
Error in dots_list(..., title = title, subtitle = subtitle, caption = caption, :
object 'price' not found
I would like the function to run in the following way, here I create the plot directly outside of a function:
diamonds |>
ggplot(aes(x = cut, y = price)) +
geom_point() +
ggtitle('price')
Produces a plot: enter image description here
How can I call my function to get the same result:
plot_eval(diamonds, price)

