またはgeom_abline
と同じプロットで使用するとエラーが発生しますが、その理由がわかりません。例えばfacet_wrap
facet_grid
# Example data
ex <- data.frame(x=1:10, y=1:10, f=gl(2, 5))
ggplot() +
geom_point(data=ex, aes(x=x, y=y)) +
geom_abline(slope=1, intercept=0) +
facet_wrap(~f)
原因Error in if (empty(data)) { : missing value where TRUE/FALSE needed
。
geom_point
後で別のデータ フレームからデータを追加するため、上でレイヤーにデータを設定しました。ベースレイヤーにデータを設定すると、別のエラーが発生するため、これは問題と関係があります。
ggplot(ex, aes(x=x, y=y)) +
geom_abline(slope=1, intercept=0) +
facet_wrap(~f)
Error in as.environment(where) : 'where' is missing
回避策
簡単な回避策があります。データ フレームを作成して 1:1 ラインを定義し、それを を使用してプロットするgeom_line
と、基本的に同じプロットが得られgeom_abline
ます...
# Define a 1:1 line with data
one_to_one <- data.frame(xO=range(ex$totalcells), yO=range(ex$totalcells))
# Plot the 1:1 line with geom_line
ggplot() +
geom_point(data=ex, aes(x=x, y=y)) +
geom_line(data=one_to_one, aes(x=xO, y=yO), colour="black") +
facet_wrap(~f)
...したがって、この質問は、問題を回避する方法ではなく、これらのエラーが発生する理由(および、それらがバグまたは予期される動作を表しているかどうか) に関するものです。