Home » R Histogram

# R Histogram

A histogram is a type of bar chart which shows the frequency of the number of values which are compared with a set of values ranges. The histogram is used for the distribution, whereas a bar chart is used for comparing different entities. In the histogram, each bar represents the height of the number of values present in the given range.

For creating a histogram, R provides hist() function, which takes a vector as an input and uses more parameters to add more functionality. There is the following syntax of hist() function:

Here,

S.NoParameterDescription
1.vIt is a vector that contains numeric values.
2.mainIt indicates the title of the chart.
3.colIt is used to set the color of the bars.
4.borderIt is used to set the border color of each bar.
5.xlabIt is used to describe the x-axis.
6.ylabIt is used to describe the y-axis.
7.xlimIt is used to specify the range of values on the x-axis.
8.ylimIt is used to specify the range of values on the y-axis.
9.breaksIt is used to mention the width of each bar.

Let?s see an example in which we create a simple histogram with the help of required parameters like v, main, col, etc.

### Example

Output: Let?s see some more examples in which we have used different parameters of hist() function to add more functionality or to create a more attractive chart.

### Example: Use of xlim & ylim parameter

Output: ### Example: Finding return value of hist()

Output: ### Example: Using histogram return values for labels using text()

Output: ### Example: Histogram using non-uniform width

Output: Next TopicR Line Graphs