Created
July 26, 2014 12:53
-
-
Save kissge/850f5b67c1fa11e02a1e to your computer and use it in GitHub Desktop.
Create a histogram from frequency list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hist.from.freq <- function (range, freq, normalize = F, main = "Histogram") { | |
wid <- s[2] - s[1] | |
range <- range - wid / 2 | |
range[length(range) + 1] <- range[length(range)] + wid | |
if (normalize) freq <- freq / sum(freq) | |
dat <- list(breaks = range, counts = freq) | |
attr(dat, "class") <- "histogram" | |
plot(dat, main = main, ylab = ifelse(normalize, "Probability", "Frequency")) | |
} | |
# usage: | |
# hist.from.freq(seq(0, 9), c(154, 105, 72, 16, 111, 103, 81, 84, 38, 158), normalize = T) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment