hist is used to draw a histogram, the following describes the role of each parameter;
1) x: The data used to draw the histogram, the value of which is a vector
code example:
Data <-C (Rep (1), Rep (2, 5), Rep (3, 6)) hist (data)
As follows:
It can be seen that the horizontal axis is a different interval, and the ordinate is the frequency of falling into the interval;
2) Break: There are many different formats for this parameter
The first: Specify a vector, giving a different breakpoint
code example:
Data <-C (Rep (1), Rep (2, 5), Rep (3, 6)) hist (data, breaks = C (0.5, 1.5, 2.5, 3.5))
As follows:
The second type: Specify the number of separated intervals, automatically calculate the size of the interval according to the number of intervals
code example:
3) Freq: Logical value, the default value is true, the y-axis shows the frequency in each interval, FALSE, the representation of the frequencies (= number/total)
code example:
Par (Mfrow = C (1, 2)) data <-C (Rep (1, Ten), Rep (2, 5), Rep (3, 6)) hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), freq = T, mai n = "Freq = T") hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), freq = f, main = "freq = f")
As follows:
4) Probability: logical value, and the Freq parameter is exactly the opposite, TRUE represents frequency, FALSE represents
code example:
Par (Mfrow = C (1, 2)) data <-C (Rep (1, Ten), Rep (2, 5), Rep (3, 6)) hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), probability = T, main = "probability = t") hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), probability = f, main = "probability = f")
As follows:
5) Labels: the label displayed above each pillar,
code example:
hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), labels = c ("A", "B", "C"))
As follows:
6) Axes: logical value, whether the axis is displayed
code example:
Par (Mfrow = C (1, 2)) data <-C (Rep (1, Ten), Rep (2, 5), Rep (3, 6)) hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), axes = T, Mai n = "axes = T") hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), axes = f, main = "axes = f")
As follows:
7) Col: Fill Color of column
code example:
Par (Mfrow = C (1, 2)) data <-C (Rep (1, Ten), Rep (2, 5), Rep (3, 6)) hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), col = "Pink") hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), col = Rainbow (3))
As follows:
8) Border: The color of the column's border, the default is black, when border = NA, represents no border
code example:
hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), col = Rainbow (3), border = NA)
As follows:
9) Densitty and angle, filling columns with lines
code example: Density control the density of filled lines
Par (Mfrow = C (1, 3)) data <-C (Rep (1, Ten), Rep (2, 5), Rep (3, 6)) hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), density = 1, main = "density = 1") hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), density = 2, main = "density = 2") hist (Dat A, breaks = C (0.5, 1.5, 2.5, 3.5), density = 3, main = "density = 3")
As follows:
code example: Angle controls the angle of the line and must be used with the density parameter in order to function
Par (Mfrow = C (1, 3)) data <-C (Rep (1, Ten), Rep (2, 5), Rep (3, 6)) hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), density = 2, Angle = $, main = "angle =") hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), density = 2, angle = all, m Ain = "angle = All") hist (data, breaks = C (0.5, 1.5, 2.5, 3.5), density = 2, angle =, main = "angle = 180" ")
As follows:
Finally, we introduce the return value of the Hist function.
Data <-C (Rep (1), Rep (2, 5), Rep (3, 6)) a <-hist (data, breaks = C (0.5, 1.5, 2.5, 3.5)) A$BREAKS[1] 0.5 1.5 2.5 3. 5$COUNTS[1] 5 6$density[1] 0.4761905 0.2380952 0.2857143$mids[1] 1 2 3$xname[1] "Data" $equidist [1] trueattr ( , "class") [1] "histogram"
As you can see from the results in the code, the return value is an object of type histogram, where breaks is the interval of separation, counts is the frequency of each interval, density is the frequencies of each interval, and Mids is the center point of each column;
Using the return value, we can use the Hist function to count the frequency distributions of a string of data in different intervals.
R Language hist Drawing function