Javatpoint Logo
Javatpoint Logo

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.No Parameter Description
1. v It is a vector that contains numeric values.
2. main It indicates the title of the chart.
3. col It is used to set the color of the bars.
4. border It is used to set the border color of each bar.
5. xlab It is used to describe the x-axis.
6. ylab It is used to describe the y-axis.
7. xlim It is used to specify the range of values on the x-axis.
8. ylim It is used to specify the range of values on the y-axis.
9. breaks It 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:

R Histogram

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:

R Histogram

Example: Finding return value of hist()

Output:

R Histogram

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

Output:

R Histogram

Example: Histogram using non-uniform width

Output:

R Histogram
Next TopicR Line Graphs




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA