different background colours for each rectangles in facet_grid

Showing 1-5 of 5 messages
different background colours for each rectangles in facet_grid conradin bolliger 12/1/10 2:17 AM
Hi
 
I would like to produce different background colours for each rectangles in
facet_grid. I use as example the one hadley gives under the following

link: https://github.com/hadley/ggplot2/wiki/Faceting-Attributes 
 
Example:
plot <- ggplot(data = xy)+
geom_point(aes(x = x, y = y))+
facet_grid(type ~ type2)
plot
## strip.background (rect)
plot + opts(strip.background = theme_rect(colour = 'purple', fill = 'pink', size
= 3, linetype='dashed'))
## if I change the fill argument to e.g. fill = c("green", "pink", "orange"),
all rectangles become green, but I would like to have for each rectangel an
other colour.
 
Can somebody help me out, how to solve this problem. Thanks a lot in advance.
Conradin


Re: different background colours for each rectangles in facet_grid Brandon Hurr 12/1/10 6:09 PM
I thought maybe it was because there were actually 5 rectangles, but even if you supply 5 colors or take away one dimension they are always green. 

Seems like we'll need someone who knows the innards a bit more to get a definite answer or workaround. 

B
Re: different background colours for each rectangles in facet_grid kohske 12/1/10 7:33 PM
hi,

perhaps it is better to edit the grid objects after plot:

plot
mapply(
  function(g, co)grid.edit(g$name, gp=gpar(fill=co)),
  grid.gget(gPath("strip_h","strip.background"),grep=T),
  c("green","blue","yellow")
  )


--
Kohske Takahashi <takahash...@gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

> --
> 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
>

Re: different background colours for each rectangles in facet_grid James McCreight 12/1/10 8:30 PM
that's some serious magic! :)
Re: different background colours for each rectangles in facet_grid Hadley Wickham 12/1/10 9:15 PM
If you want to change the background colour, I think it's easier to
use geom_rect with xmin and ymin = -Inf and xmax and ymax = Inf.

Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/