A histogram contains a rectangular area to display the statistical information which is proportional to the frequency of a variable and its width in successive numerical intervals. A graphical representation that manages a group of data points into different specified ranges. It has a special feature that shows no gaps between the bars and is similar to a vertical bar graph.
We can create histograms in R Programming Language using the hist() function.
Syntax:
hist(v, main, xlab, xlim, ylim, breaks, col, border)
Parameters:
- v: A vector containing numerical values for the histogram.
- main: The title of the chart.
- col: The color of the bars.
- xlab: The label for the x-axis.
- border: The border color of each bar.
- xlim: The range of values for the x-axis.
- ylim: The range of values for the y-axis.
- breaks: The width of each bar.
1. Creating a simple Histogram in R
Creating a simple histogram chart by using the above parameter. This vector v is plot using hist().
Example:
v <- c(19, 23, 11, 5, 16, 21, 32, 14, 19, 27, 39)
hist(v, xlab = "No.of Articles ",
col = "green", border = "black")
Output:

1.1 Range of X and Y values
To describe the range of values we need to do the following steps:
- We can use the xlim and ylim parameters in X-axis and Y-axis.
- Take all parameters which are required to make a histogram chart.
Example
v <- c(19, 23, 11, 5, 16, 21, 32, 14, 19, 27, 39)
hist(v, xlab = "No.of Articles", col = "green",
border = "black", xlim = c(0, 50),
ylim = c(0, 5), breaks = 5)
Output:

2. Using histogram return values for labels using text()
To create a histogram return value chart.
v <- c(19, 23, 11, 5, 16, 21, 32, 14, 19, 27, 39, 120, 40, 70, 90)
m<-hist(v, xlab = "Weight", ylab ="Frequency",
col = "darkmagenta", border = "pink",
breaks = 5)
text(m$mids, m$counts, labels = m$counts,
adj = c(0.5, -0.5))
Output:

3. Histogram using non-uniform width
Creating different width histogram charts, by using the above parameters, we created a histogram using non-uniform width.
Example
v <- c(19, 23, 11, 5, 16, 21, 32, 14, 19, 27, 39, 120, 40, 70, 90)
hist(v, xlab = "Weight", ylab ="Frequency",
xlim = c(50, 100),
col = "darkmagenta", border = "pink",
breaks = c(5, 55, 60, 70, 75,
80, 100, 140))
Output:
