R Programming language - R Histogram

In R, you can create a histogram using the hist() function. The hist() function takes one or more vectors of values to plot, and several optional arguments to customize the appearance of the plot.

Here is a basic example of how to create a histogram in R:

refer to:‮figi‬tidea.com
# Create a vector of values to plot
values <- c(10, 20, 30, 40, 50)

# Create a histogram of the values
hist(values)

This will create a simple histogram with bins representing the range of values in the vector.

You can customize the appearance of the histogram by using the optional arguments of the hist() function. For example, you can change the number of bins by setting the breaks argument:

# Create a histogram of the values with 3 bins
hist(values, breaks = 3)

You can also add a title to the plot using the main argument:

# Create a histogram of the values with a title
hist(values, main = "My Histogram")

You can create a cumulative histogram by setting the freq argument to FALSE:

# Create a cumulative histogram of the values
hist(values, freq = FALSE)

In addition, you can create a density histogram by setting the density argument to TRUE:

# Create a density histogram of the values
hist(values, density = TRUE)

You can also customize the colors of the bars and the border of the bars using the col and border arguments, respectively:

# Create a histogram of the values with custom colors
hist(values, col = "red", border = "blue")