Next →

Output:


      

Plots:

Histograms

Histograms are used to visualize the distribution of numerical data. They show how frequently values fall within specific intervals (bins). In R, you can create histograms using the base hist() function or ggplot2.

Basic Histogram

# Sample data
values <- c(5, 7, 8, 5, 6, 7, 8, 9, 5, 6)

# Create a histogram
hist(values, main = "Basic Histogram", xlab = "Values", col = "lightblue", border = "black")

Using ggplot2

library(ggplot2)

df <- data.frame(values = values)

ggplot(df, aes(x = values)) +
  geom_histogram(binwidth = 1, fill = "orange", color = "black") +
  ggtitle("Histogram with ggplot2") +
  theme_minimal()

Histograms help you understand the shape of your data and identify patterns such as skewness or outliers.