Histogram ये दो values के बीच का वर्णन करता है | ये bar plot से काफी मिलता-जुलता है लेकिन histogram ये लगातार आने वाले values का समूह करता है | Histogram में दो values के range में आनेवाले सभी values को अपनी ऊंचाई से वर्णन करता है |
R में Histograms को create करने के लिए 'hist()' function का इस्तेमाल किया जाता है |
Syntax for hist() Function in R
hist(x,main,xlab,ylab,breaks,xlim,ylim,col,border,freq)
Parameters for hist() Function in R
x : vector. यहाँ पर numeric vector दिया जाता है |
main : string. histogram chart को title दिया जाता है | default main 'Histogram of variable_name' होता है |
xlab : string. x-axis को label दिया जाता है | default xlab 'vector'या उसका variable_name होता है |
ylab : string. y-axis को label दिया जाता है | default ylab 'Frequency' होता है |
breaks : numeric or vector. हर bar के width को दिया जाता है |
xlim : vector. x-axis की limit को दिया जाता है |
ylim : vector. y-axis की limit को दिया जाता है |
col : string or vector. हर bar को color दिया जाता है |
border : string. bars के border का color दिया जाता है |
Simple Example for histogram in R
Example पर simple hist() function से histogram chart को create किया गया है |
Source Code :vector = c(25,10,15,35,45,74,87,12,101) hist(vector)
1.png)
Add Custom Title, x label and y label on histogram in R
Example पर title, x label और y label को set किया गया है |
Source Code :vector = c(25,10,15,35,45,74,87,12,101) hist(vector, main = 'My First Histogram', xlab = 'X-axis', ylab = 'Y-axis')
2.png)
Add colors on histogram in R
Example पर histogram के bars को तीन colors से color किया गया है |
Source Code :vector = c(25,10,15,35,45,74,87,12,101) colors = c('red','green','blue') hist(vector, main = 'My First Histogram', xlab = 'X-axis', ylab = 'Y-axis', col = colors)
3.png)
Example for hist() function with breaks parameter in R
Example पर breaks इस parameter की मदद से bar की width को increase किया गया है |
Source Code :vector = c(25,10,15,35,45,74,87,12,101) colors = c('red','green','blue') hist(vector, main = 'My First Histogram', xlab = 'X-axis', ylab = 'Y-axis', col = colors, breaks = 2)
4.png)