データを使用ggplot_build
してから抽出します。これを試して:
gg <- ggplot_build(g)
結果のオブジェクトはリストであり、最初の要素には目的のデータが含まれています。
str(gg, max.level=1)
List of 3
$ data :List of 1
$ panel:List of 5
..- attr(*, "class")= chr "panel"
$ plot :List of 8
..- attr(*, "class")= chr "ggplot"
これは次のようになります。
head(gg$data[[1]])
y x binwidth count ncount width PANEL group countidx stackpos xmin xmax ymin ymax
1 0 -2.070496 0.1356025 1 0.125 0.1356025 1 1 1 0.5 -2.138297 -2.002695 0 1
2 0 -1.781799 0.1356025 2 0.250 0.1356025 1 1 1 0.5 -1.849600 -1.713998 0 1
3 0 -1.781799 0.1356025 2 0.250 0.1356025 1 1 2 1.5 -1.849600 -1.713998 0 1
4 0 -1.619960 0.1356025 1 0.125 0.1356025 1 1 1 0.5 -1.687761 -1.552159 0 1
5 0 -1.403223 0.1356025 6 0.750 0.1356025 1 1 1 0.5 -1.471024 -1.335422 0 1
6 0 -1.403223 0.1356025 6 0.750 0.1356025 1 1 2 1.5 -1.471024 -1.335422 0 1
PS。私の知る限り、この機能はggplot2
バージョン 0.9.0でのみ利用可能になりました