(As per my initial suggestion and your confirmation)
It was about how you were trying to pass string arguments of variable names into your fn.
- on the command-line,
ggplot(gdf, aes(first, second))
would work fine - but inside your function, you're also passing in first,second as string variables. So yes you would now need
aes_string(first,second)
inside your function testfn, since you're now passing variable names indirectly, through the string-variables first,second. - also since the variable-names
first,second
are strings, yes you do need to quote them when you call the fn. (I'm not sure what language mechanism ggplot'saes()
uses to not need strings, but whatever. Use quotes.) - see also the
quote()
command in R