次の例では、2 つの一連の点を作成し、 を使用してそれらをプロットしますggplot2
。また、値に基づいていくつかのポイントを強調表示します
library(ggplot2)
x <- seq(0, 6, .5)
y.a <- .1 * x -.1
y.b <- sin(x)
df <- data.frame(x=x, y=y.a, case='a')
df <- rbind(df, data.frame(x=x, y=y.b, case='b'))
print(ggplot(df) + geom_point(aes(x, y), color=ifelse(df$y<0, 'red', 'black')))
そして、これが結果です
case
ここで、強調表示スキームを維持しながら、2 つの を 2 つのファセットに分けたいと思います。
> 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
これはどのように達成できますか?