r - Need to extract data from the ggplot geom_histogram -


hi have made plot using ggplot2 geom_histogram function data frame see sample below , link ggplot histogram need label each geom_vline factors using nested ddply function , facet wrap

now need make data frame contains summarized data used in plot above. can help? in advance. g

sector2 family  year    length bun acroporidae 2010    332.1300496 bun poritidae   2011    141.1467966 bun acroporidae 2012    127.479 bun acroporidae 2013    142.5940556 mur faviidae    2010    304.0405 mur faviidae    2011    423.152 mur pocilloporidae  2012    576.0295 mur poritidae   2013    123.8936667 nth faviidae    2010    60.494 nth faviidae    2011    27.427 nth pocilloporidae  2012    270.475 nth poritidae   2013    363.4635 

to values plotted can use function ggplot_build() argument plot.

p <- ggplot(mtcars,aes(mpg))+geom_histogram()+       facet_wrap(~cyl)+geom_vline(data=data.frame(x=c(20,30)),aes(xintercept=x))  pg <- ggplot_build(p) 

this make list , 1 of sublists named data. sublist contains dataframe values used in plot, example, histrogramm contains y values (the same count). if use facets column panel shows in facet values used. if there more 1 geom_ in plot data contains dataframes each - in example there 1 dataframe histogramm , vlines.

head(pg$data[[1]])   y count         x ndensity ncount density panel group ymin ymax 1 0     0  9.791667        0      0       0     1     1    0    0 2 0     0 10.575000        0      0       0     1     1    0    0 3 0     0 11.358333        0      0       0     1     1    0    0 4 0     0 12.141667        0      0       0     1     1    0    0 5 0     0 12.925000        0      0       0     1     1    0    0 6 0     0 13.708333        0      0       0     1     1    0    0       xmin     xmax 1  9.40000 10.18333 2 10.18333 10.96667 3 10.96667 11.75000 4 11.75000 12.53333 5 12.53333 13.31667 6 13.31667 14.10000  head(pg$data[[2]])   xintercept panel group xend  x 1         20     1     1   20 20 2         30     1     1   30 30 3         20     2     2   20 20 4         30     2     2   30 30 5         20     3     3   20 20 6         30     3     3   30 30 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -