I want to pass to ggplot an x and a y variable where the names come from another data frame.
I thought it would be possible to use the aes_string() argument and pass the column names from data1 but use the data from data2.
data(iris)
data1 <- iris
data2 <- data
dev.off()
ggplot() +
geom_point(aes_string(
x = rlang::eval_tidy(colnames(data1)[1]),
y = rlang::eval_tidy(colnames(data1)[2])
), data = data2
)
How can I pass the variable names using something similar to eval_tidy?