histogram - r - hist function aggregates "zero" and "1" values into one bin. -
i'm getting crazy hist() function. have dataset follows:
table(data) 0 1 2 3 4 5 7 8 85 7 3 4 6 1 2 1 so expect hist(data, labels=true) returns me histogram 9 bins, 1 zeros, 1 ones, etc. , value on each bin. aggregates 0s , 1s , after 1 day of search on google, still cannot figure out how can prepare it. tried declare number of bins hist(data, breaks=c(0,8)) nothing. alternative, tried histogram of lattice package, , works fine... cannot figure out how have value of each bin displayed... can help me either way (having right number of columns hist() or having bins values displayed histogram())? much.
hist(...) uses right-closed intervals default. can alter using right=... argument.
x <- c(0, 1, 2, 3, 4, 5, 7, 8) y <- c(85, 7, 3, 4, 6, 1, 2, 1) z <- rep(x,times=y) par(mfrow=c(1,2)) hist(z,right=t, main="right closed") hist(z,right=f, main="left closed") here's equivalent in ggplot, imo bit clearer.
library(ggplot2) ggplot(data.frame(z), aes(x=factor(z))) + geom_histogram(fill="lightgreen", color="grey50") r histogram
No comments:
Post a Comment