[R] ggplot2 argument handling odd

hadley wickham h.wickham at gmail.com
Thu Mar 27 13:57:35 CET 2008


>  Ok, I will try that, thanks. BTW, where is this aes_string option
>  documented, sounds useful? How could I do the same thing with facetting?
>  If I want to save something like ". ~ groupVar" as a string in a
>  variable, could I pass it with facet_string to ggplot?

It's a see also from ?aes (or at least it is in the development
version).  facet_grid should already accept a string instead of a
function, so it should just work.

>  But anyway, I would be curious how to do it with qplot. The basic
>  question is: How to pass the string of a variable to a function which is
>  supposed to interpret it. Aka:
>
>  var <- "magicVar"
>
>  fun(doSomeMagic(var))
>
>  doSomeMagic should then write magicVar at the place.

In general, you can use as.name, substitute and eval:

x <- as.name("mpg")
y <- as.name("wt")

eval(substitute(qplot(x, y, data=mtcars), list(x=x, y=y)))

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list