[R] Graph binned data
David Winsemius
dwinsemius at comcast.net
Mon Nov 7 06:26:15 CET 2011
On Nov 7, 2011, at 12:09 AM, Jeffrey Joh wrote:
>
> I have a table that looks like this:
>
> structure(list(speed = c(3,9,14,8,7,6), result = c(0.697, 0.011,
> 0.015, 0.012, 0.018, 0.019), house = c(1,
> 1, 1, 1, 1, 1), date = c(719, 1027, 1027, 1027, 1030, 1030),
> id = c("1000", "10000",
> "10001", "10002", "10003", "10004")), .Names = c("speed",
> "result", "house", "date", "id"), class = "data.frame", row.names =
> c("1000",
> "10000", "10001", "10002", "10003", "10004"))
>
> I would like to bin the data by speed, 0-4, 5-9, 10-14, 15-20, etc.
?cut
> Then I would like to make a graph of speed vs result. The graph
> should show the average result of each bin,
?tapply
?mean
dat$sgrp <- cut(dat$speed, c(0,5,10, 15, 20), include.lowest=TRUE,
right=TRUE)
plot( tapply(dat$speed, dat$sgrp, mean), xaxt="n", ylim=c(0,20))
axis(1, at= 1:4, labels = levels(dat$sgrp) )
> and error bars to represent the standard deviation of the result in
> each bin. What kind of code can I use to make this?
(This would seem to be pretty basic material. Why don't you do further
study of whatever introductory texts you are using.) The CI's can be
added with one of the functions in package 'plotrix'.
>
> Jeffrey
>
> ______________________________________________
> R-help at r-project.org 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list