Triad sou.

"..count.. + facet_grid" の挙動について

追記

ggplot-0.9.1 で修正されていました!
ggplot-0.9.1 での実行結果

メモ

スクリプトの書き方が良くないのかもしれませんが、..count..facet_gridを併用したときの挙動をメモっておきます。
バージョンは R-2.15.0 + ggplot-0.9.0 です。


こう書くと全ての度数が 1 になってしまう。

require("ggplot2")

mydf1 <- data.frame(
  x = sample(letters[1:2], 500, replace = T),
  y = sample(letters[10:11], 500, replace = T)
)

ggplot(mydf1, aes(x = x, y = ..count..)) +
  geom_bar() + facet_grid( ~ y) + opts(title = "..count.. + facet_grid")


facet_wrap の場合は意図したグラフが得られました。

ggplot(mydf1, aes(x = x, y = ..count..)) +
  geom_bar() + facet_wrap( ~ y) + opts(title = "..count.. + facet_wrap")


また、データフレームに id 変数を加えてみると facet_wrap の結果と一致しました。

mydf2 <- data.frame(
  mydf1,
  id = 1:500
)
ggplot(mydf2, aes(x = x, y = ..count..)) +
  geom_bar() + facet_grid( ~ y) + opts(title = "..count.. + facet_grid + id"))


何でだろう。
多分 ..count.. の挙動を良く理解していないからだろう。