Last active
September 26, 2017 08:33
-
-
Save aravindhebbali/7dbcd02b37e80c5262133d0464b7e8c9 to your computer and use it in GitHub Desktop.
Data Visualization: Histogram
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
# distributions | |
# normal distribution | |
hist(rbeta(10000, 5, 5), ann = FALSE, col = 'blue') | |
# skewed distributions | |
hist(rbeta(10000, 2, 5), ann = FALSE, col = 'blue') | |
hist(rbeta(10000, 5, 2), ann = FALSE, col = 'blue') | |
# histogram | |
# store the results of hist function | |
h <- hist(mtcars$mpg) | |
# display number of breaks | |
h$breaks | |
# frequency of the intervals | |
h$counts | |
# frequency density | |
h$density | |
# mid points of the intervals | |
h$mids | |
# varible name | |
h$xname | |
# whether intervals are of equal size | |
h$equidist | |
# bins | |
hist(mtcars$mpg, breaks = 10) | |
# intervals | |
hist(mtcars$mpg, breaks = c(10, 18, 24, 30, 35)) | |
hist(mtcars$mpg, breaks = 'Sturges') | |
hist(mtcars$mpg, breaks = 'Scott') | |
hist(mtcars$mpg, breaks = 'FD') | |
# frequency density | |
hist(mtcars$mpg, probability = TRUE) | |
# color | |
hist(mtcars$mpg, col = 'blue') | |
# border color | |
hist(mtcars$mpg, border = 'red') | |
# labels | |
hist(mtcars$mpg, labels = TRUE) | |
hist(mtcars$mpg, labels = c("6", "12", "8", "2", "4")) | |
# putting it all together | |
hist(mtcars$mpg, labels = TRUE, prob = TRUE, | |
ylim = c(0, 0.1), xlab = 'Miles Per Gallon', | |
main = 'Distribution of Miles Per Gallon', | |
col = rainbow(5)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment