Yes, that did work (and I just learned about piping as well, so thanks for that).
I also realized that the "data" in the first line of code is also passed to the aes() line. Thus, the inclusion of that data$ was not necessary in the first place.
Now I've tried to replicate this using cor.test and tried
data %>%
cor.test(x = var1, y = var2, use = "complete.obs")
This did not run and returns the error: Error in match.arg(alternative) : object 'var2' not found
I also tried this, and this also didn't work:
cor.test(data = data,
x = var1,
y = var2,
use = "complete.obs")
The error returned here is: object 'var1' not found
But this does run:
cor.test(x = data$var1, y = data$var2, use = "complete.obs")