With missing background in informatics I have difficulties to understand the differences between aes
and aes_string
in ggplot2 and its implications
aes
saves you some typing as you don't need the quotes. That is all. You are of course free to always use aes_string
. You should use aes_string
if you want to pass the variable names programmatically.
Internally aes
uses match.call
for the non-standard evaluation. Here is a simple example for illustration:
fun <- function(x, y) as.list(match.call())
str(fun(a, b))
#List of 3
# $ : symbol fun
# $ x: symbol a
# $ y: symbol b
For comparison:
library(ggplot2)
str(aes(x = a, y = b))
#List of 2
# $ x: symbol a
# $ y: symbol b
The symbols are evaluated at a later stage.
aes_string
uses parse
to achieve the same:
str(aes_string(x = "a", y = "b"))
#List of 2
# $ x: symbol a
# $ y: symbol b