Open3
ggplot2::after_stat()に関してまとめる
ピン留めされたアイテム
- 古いverのggplot2では
..count..
のように指定していたものが、after_stat()
で利用できる - generated variables / computed variables と呼ぶ。
- ggplot2内部で計算される変数という理解
- 各関数
stat_*
のヘルプを見れば、何が計算されるかわかる- e.g.)
geom_bar / stat_bar
の場合はprop / count
- e.g.)
下記のサイトに一覧としてまとまっている
下記のコードで変数を見ることが可能
p <- ggplot_build(ggplot(diamonds, aes(x = carat)) + geom_histogram())
#> names(p)
#> [1] "data" "panel" "plot"
dplyr::glimpse(p$data[[1]])
geom_bar()
のprop
を使ったサンプル
ggplot() +
geom_bar(aes(y = after_stat(prop))
geom_density()
でafter_stat(scaled)
を使う場合
ggplot(diamonds, aes(x = depth, fill = cut, colour = cut)) +
geom_density(alpha = 0.1)
ggplot(diamonds, aes(x = depth, fill = cut, colour = cut)) +
geom_density(aes(y = after_stat(scaled)), alpha = 0.1)