Troubel mapping facet panel colors to a variable

209 views
Skip to first unread message

Raphael Mazor

unread,
Mar 16, 2012, 2:27:53 AM3/16/12
to ggp...@googlegroups.com
I am trying to map the color of a panel to a factor ("condition") in a
dataframe ("df"), but I don't think I'm going it right. The facets are
actually mapped to a different variable ("site").

facet_wrap( ~site ) + opts(panel.background = theme_rect( aes( df, fill
= condtion )))

When I do this, the backgrounds are all blank, and I get one warning for
each level of y:

In grid.Call.graphics(L_rect, x$x, x$y, x$width, x$height, ... :
supplied color is not numeric nor character

Any advice would be greatly appreciated!

--
Raphael D. Mazor
Freshwater Biologist
Southern California Coastal Water Research Project
3535 Harbor Blv Suite 110
Costa Mesa, CA 92626

Tel. (714) 755-3235
Fax. (714) 755-3299

Joran

unread,
Mar 16, 2012, 2:11:33 PM3/16/12
to ggp...@googlegroups.com
Maybe you are looking for something like this:

dat <- data.frame(x = runif(16),
          y = runif(16),
  grp = rep(letters[1:4],each = 4))
 
ggplot(dat,aes(x = x,y = y)) +
facet_wrap(~grp) + 
geom_rect(aes(fill = grp),xmin = -Inf,xmax = Inf,ymin = -Inf,ymax = Inf,alpha = 0.2) + 
geom_point()

Raphael Mazor

unread,
Mar 18, 2012, 6:52:15 PM3/18/12
to ggp...@googlegroups.com
Thanks, I was able to get what I wanted (that is, to use a different variable for panel color than the one I used for facetting) by modifying your script!


dat <- data.frame(x = runif(16),
          y = runif(16),
  grp = rep(letters[1:4],each = 4),
  grp.type = rep(c("E","F"),each = 8))


ggplot(dat,aes(x = x,y = y)) +
facet_wrap(~grp) +
geom_rect(aes(fill = grp.type),xmin = -Inf,xmax = Inf,ymin = -Inf,ymax = Inf,alpha = 0.2) +
geom_point()

Thanks!!!





Raphael D. Mazor
Freshwater Biologist
Southern California Coastal Water Research Project
3535 Harbor Blv Suite 110
Costa Mesa, CA 92626

Tel. (714) 755-3235
Fax. (714) 755-3299

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
Reply all
Reply to author
Forward
0 new messages