[R] creating bins for a plot

Alex Brown alex at transitive.com
Thu Oct 19 12:53:07 CEST 2006


I suggest you look at the functions cut and tapply.

for instance:

breaks = 0:40 / 40
bucket <- cut(purban2, breaks)
used.c = tapply(used, bucket, sum)
unused.c = tapply(1 - used, bucket, sum)
used.c[is.na(used.c)] = 0
unused.c[is.na(unused.c)] = 0
plot(breaks[-length(breaks)], used.c / unused.c)

-Alex Brown

On 18 Oct 2006, at 23:24, Jeffrey Stratford wrote:

> Hi.  I'm trying to plot the ratio of used versus unused bird houses
> (coded 1 or 0) versus a continuous environmental gradient  
> (proportion of
>  urban cover [purban2]) that I would like to convert into bins (0 -
> 0.25, 0.26 - 0.5, 0.51 - 0.75, 0.76 - 1.0) and I'm not having much  
> luck
> figuring this out.  I ran a logistic regression and purban2 ends up
> driving the probability of a box being occupied so it would be nice to
> show this relationship.  I'm also plotting the fitted values vs.  
> purban2
> but that's done.  Any suggestions would be appreciated.
>
> Many thanks,
>
> Jeff
>
>
> Data sample:
>
> box	use	purbank	purban2
> 1	1	0.003813435	0.02684564
> 2	1	0.04429451	0.1610738
> 3	1	0.04458785	0.06040268
> 4	1	0.06072162	0.2080537
> 5	0	0.6080962	0.6979866
> 6	1	0.6060428	0.6107383
> 7	1	0.3807568	0.4362416
> 8	0	0.3649164	0.3154362
> 9	0	0.3505427	0.2483221
> 10	0	0.3476093	0.1409396
> 11	0	0.3719566	0.3020134
> 12	1	0.09238011	0.1342282
> 13	0	0.08616111	0.1073826
> 14	0	0.07388724	0.04026845
> 15	1	0.07046477	0.03355705
> .
> .
> .
>
>
> ****************************************
> Jeffrey A. Stratford, Ph.D.
> Postdoctoral Associate
> 331 Funchess Hall
> Department of Biological Sciences
> Auburn University
> Auburn, AL 36849
> 334-329-9198
> FAX 334-844-9234
> http://www.auburn.edu/~stratja
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list