Rainer M Krug
2008-Jan-27 10:23 UTC
[R] Putting frame around single panels in ggplot 2 and facet_grid()
Hi I want to highlight two panels in a grid created with facet_grid() by putting a box around it or usiong another background colour. Is this possible, and if yes, how? Thanks Rainer -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Plant Conservation Unit Department of Botany University of Cape Town Rondebosch 7701 South Africa Tel: +27 - (0)21 650 5776 (w) Fax: +27 - (0)86 516 2782 Fax: +27 - (0)21 650 2440 (w) Cell: +27 - (0)83 9479 042 Skype: RMkrug Google Chat: R.M.Krug at gmail.com email: Rainer at krugs.de
hadley wickham
2008-Jan-27 17:51 UTC
[R] Putting frame around single panels in ggplot 2 and facet_grid()
On Jan 27, 2008 4:23 AM, Rainer M Krug <r.m.krug at gmail.com> wrote:> Hi > > I want to highlight two panels in a grid created with facet_grid() by > putting a box around it or usiong another background colour. Is this > possible, and if yes, how?It's possible, but not particularly easy. You could do something like: # Background colours background <- data.frame( cyl = c(4, 6, 8), fill = c(NA, alpha("red", 0.2), alpha("black", 0.3)) ) # Points defining square region for background square <- with(mtcars, data.frame( x = c(min(mpg), max(mpg), max(mpg), min(mpg)), y = c(min(wt), min(wt), max(wt), max(wt)) )) ggplot(mtcars, aes(x=mpg, y=wt)) + geom_polygon(aes(x=x,y=y, fill=fill), data=merge(background, square)) + geom_point() + scale_fill_identity() + facet_grid(. ~ cyl) Hadley -- http://had.co.nz/