I have two data frames with two columns each, however, each dataframe has unique variable names. I would like to specify the data in a call to ggplot and then, when mapping aesthetics to x and y for a column plot, to call the data anonymously and use indexing to specify which column goes to which aesthetic rather than using the variable names.
Tried using the .data pronoun, but it does not work with indexing. The below code works fine when specifying the variable name inside [[]].
library(tidyverse)
df1 <- data.frame(col1 = 1:10, col2 = 11:20)
df2 <- data.frame(var1 = 21:30,var2 = 31:40)
p <- geom_col(mapping = aes(x = .data[[,1]], y = .data[[,2]]))
ggplot(data = df1)+p
ggplot(data = df2)+p