3

またはgeom_ablineと同じプロットで使用するとエラーが発生しますが、その理由がわかりません。例えばfacet_wrapfacet_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)

ここに画像の説明を入力

...したがって、この質問は、問題を回避する方法ではなく、これらのエラーが発生する理由(および、それらがバグまたは予期される動作を表しているかどうか) に関するものです。

4

1 に答える 1

2

以下の作品:

ggplot(ex, aes(x=x, y=y)) + geom_point() + 
  geom_abline(slope=1, intercept=0) +
  facet_wrap(~f)

geom_point()2番目の例に基づいて、追加したことに注意してください。

于 2013-09-01T05:19:07.820 に答える