Re: [R] use ggplot in a function to which a column name is given

2007-12-13 Thread hadley wickham
> great! I knew you would have thought this through. That's perfect. As > always there's the trade-off between writing code and documenting the > code already written. In this case the trade-off turned toward the > code part I guess. > > Autodetection of strings by aes would be even greater but tha

Re: [R] use ggplot in a function to which a column name is given

2007-12-13 Thread jiho
On 2007-December-13 , at 15:56 , hadley wickham wrote: > Hi Jiho, > > The key to solving this problem is to use aes_string instead of aes. > Instead of the complicated munging that aes does to get the names of > the variables, aes_string works directly with strings, so that: > > aes_string(x = "m

Re: [R] use ggplot in a function to which a column name is given

2007-12-13 Thread hadley wickham
Hi Jiho, The key to solving this problem is to use aes_string instead of aes. Instead of the complicated munging that aes does to get the names of the variables, aes_string works directly with strings, so that: aes_string(x = "mpg", y = "wt") == aes(x = mpg, y = wt) So your function would look l

Re: [R] use ggplot in a function to which a column name is given

2007-12-13 Thread jiho
Follow up. On 2007-December-13 , at 10:45 , jiho wrote: > foo1 <- function(uv="u") > { > # solution 1: do not use the data argument at all > # (forces the use of qplot, could be more elegant) > B = A[A$y<=5,] > qplot(B$x, B$y, fill=B[[uv]], geom="tile") > } ---> act

[R] use ggplot in a function to which a column name is given

2007-12-13 Thread jiho
Hi everyone, Hi ggplot users in particular, ggplot makes it very easy to plot things given their names when you use it interactively (and therefore can provide the names of the columns). qplot(x,foo,data=A) where A has columns (x,y,foo,bar) for example but I would like to use this fro