On Jan 27, 2008 4:23 AM, Rainer M Krug <[EMAIL PROTECTED]> 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/
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.