2012-02-22 1 views
4

私はヒストグラムを生成するためにqplot関数を使用しています。それは素敵なプロットを生成し、私はグラフィックスにとても満足しています。私はまた、ヒストグラムデータを印刷したいのですが、返すオブジェクトはqplot()から取得する方法はありますか?私はplot = FALSEオプションを追加するとデータを与えるhist()関数を使用していましたが、qplot()と同じではありません。ヒストグラムデータfrom qplot

+1

これは、3月1日にCRANにリリースされる予定のggplot2バージョン0.3で可能になると思います。 – Andrie

+2

その間に、明示的に区切りを指定するのが最善です(そうすると、どこにあるのかが分かります)。 –

+0

@Andrie 0.9、0.3ではなく; -p – kohske

答えて

0
library(gridExtra) 
library(gtable) 

fakeDF <- data.frame(group = sample(c('a', 'b', 'c', 'd'), 50, replace = T), 
       rand = sample(50:100, 50)) 

plot <- ggplot(fakeDF, aes(x = group, y = rand, group = group, fill = group)) + 
    geom_bar(stat = 'identity') 

table <- tableGrob(head(fakeDF)) 

grid.arrange(plot, 
      table, 
      ncol = 2) 

enter image description here

1

あなたはggplot()ヒストグラムを作るために使用される実際のデータを取得する機能ggplot_build()を使用することができます。それらはリスト要素dataに格納されています - 小数点は列xにあり、数は列countにあります。

p<-ggplot_build(ggplot(movies,aes(x=rating))+geom_histogram()) 

head(p$data[[1]]) 
    y count x ndensity  ncount  density PANEL group ymin ymax xmin xmax 
1 0  0 0.75 0.00000000 0.00000000 0.000000000  1  1 0 0 0.6 0.9 
2 150 150 1.05 0.02967946 0.02967946 0.008505137  1  1 0 150 0.9 1.2 
3 122 122 1.35 0.02413930 0.02413930 0.006917512  1  1 0 122 1.2 1.5 
4 199 199 1.65 0.03937475 0.03937475 0.011283482  1  1 0 199 1.5 1.8 
5 366 366 1.95 0.07241789 0.07241789 0.020752535  1  1 0 366 1.8 2.1 
6 409 409 2.25 0.08092600 0.08092600 0.023190674  1  1 0 409 2.1 2.4 
関連する問題