In the following example, I create two series of points and draw them with ggplot2 . I also highlight several points based on their values
library(ggplot2) x <- seq(0, 6, .5) ya <- .1 * x -.1 yb <- sin(x) df <- data.frame(x=x, y=ya, case='a') df <- rbind(df, data.frame(x=x, y=yb, case='b')) print(ggplot(df) + geom_point(aes(x, y), color=ifelse(df$y<0, 'red', 'black')))
And here is the result

Now I want to split two case into two faces, preserving the allocation scheme
> print(ggplot(df) + geom_point(aes(x, y), color=ifelse(df$y<0, 'red', 'black')) + facet_grid(case ~. ,)) Error: Incompatible lengths for set aesthetics: colour
How can this be achieved?
source share