Using stat_bin count to calculate y

54 views
Skip to first unread message

PeterT

unread,
Jan 21, 2011, 5:32:56 PM1/21/11
to ggplot2
ggurus,

I have data that contains a dependent variable (interp_dbh), weighting
factor (baf) and group membership (std_id). each group only has one
weighting factor i.e there are no std_id with multiple baf . I am
planning to facet the plot by group membership. I would like to plot a
histogram with the y value calculated as the product of the stat_bin
count * the weighting factor (baf). I have a method for generating the
y values in a python script and passing the values back to ggplot but
wondered if you all might have any suggestions for accomplishing this
just with ggplot . A snippet of the data is shown below.

Thanks very much,

Peter

interp_dbh | baf | std_id
------------+-----+--------
30.7517 | 40 | 202
21.0084 | 40 | 301
20.063 | 40 | 301
42.0814 | 30 | 206
31.3362 | 30 | 206
37.4404 | 30 | 206
35.2948 | 30 | 206
38.2925 | 30 | 206
43.1945 | 30 | 206
30.523 | 30 | 206
33.1178 | 30 | 206
36.2476 | 30 | 206
29.1484 | 30 | 206
28.5038 | 30 | 206
5.37572 | 30 | 206
5.43831 | 30 | 206
20.8259 | 40 | 301
22.4119 | 40 | 301
18.4468 | 40 | 301
18.907 | 40 | 301
19.9631 | 40 | 301
18.5843 | 40 | 301
19.1226 | 40 | 301

Hadley Wickham

unread,
Jan 22, 2011, 12:42:40 AM1/22/11
to PeterT, ggplot2
stat_bin already knows how to deal with weights - just use the weight aesthetic.
Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

PeterT

unread,
Jan 22, 2011, 7:20:45 PM1/22/11
to ggplot2
is it possible to use variable bin widths? I'd like to use
binboundaries defined by natural breaks (Jenks) in the data.

Hadley Wickham

unread,
Jan 23, 2011, 1:52:44 PM1/23/11
to PeterT, ggplot2
Yes, just use the breaks parameter.
Hadley
Reply all
Reply to author
Forward
0 new messages