[R] ggplot2: mapping categorical variable to color aesthetic with faceting

2009-10-06 Thread Bryan Hanson
Hello Again... I¹m making a faceted plot of a response on two categorical variables using ggplot2 and having troubles with the coloring. Here is a sample that produces the desired plot: compareCats - function(data, res, fac1, fac2, colors) { require(ggplot2) p - ggplot(data, aes(fac1,

Re: [R] ggplot2: mapping categorical variable to color aesthetic with faceting

2009-10-06 Thread baptiste auguie
Hi, I may be missing an important design decision, but could you not have only a single data.frame as an argument of your function? From your example, it seems that the colour can be mapped to the fac1 variable of data, compareCats - function(data) { require(ggplot2) p - ggplot(data,

Re: [R] ggplot2: mapping categorical variable to color aesthetic with faceting

2009-10-06 Thread baptiste auguie
Further to my previous reply, it occurred to me that ggplot2 would only ever use data and colors in your calls to compareCats(): res = res, fac1 = fac1, fac2 = fac2 have no effect whatsoever. If you want the user to be able to specify the variables used in the ggplot2 call, you probably want to

Re: [R] ggplot2: mapping categorical variable to color aesthetic with faceting

2009-10-06 Thread Bryan Hanson
Hi Baptiste: Thanks for the suggestion. It will work perfectly. I would have never considered assigning a color to a variable that contained no colors at all! I guess this is part of the aesthetic concept, which I haven't had time to reflect on much. Then later, specify a manual color scale

Re: [R] ggplot2: mapping categorical variable to color aesthetic with faceting

2009-10-06 Thread Bryan Hanson
A few days ago on the list I had wrestled with the aes() vs aes_string() issue, along with the same issue with facetting. The way I ended up handling the point you bring up, Baptiste, is perhaps rather inefficient but my data sets are not large. I allow the user to pass variables, then I use