Distribution Numerical
Histogram
ggplot2: geom_histogram() · Package: ggplot2 · Variables: 1 numerical
WHAT IS A HISTOGRAM?
A histogram groups a continuous variable into equal-width bins and shows the frequency (count) in each bin as a bar. It reveals the distribution shape — is it symmetric, skewed left or right, bimodal, or uniform? Histograms answer "how is my data distributed?" and are essential for understanding spread, central tendency, and outliers before any deeper analysis. The number of bins matters: too few bins hide patterns, too many create noise. A common rule of thumb is the square root of n. In ggplot2, use geom_histogram() and adjust the bins or binwidth parameter.
BEST FOR
- · Understanding distribution shape
- · Identifying skewness
- · Finding outliers
- · Assessing spread
AVOID WHEN
- · Categorical data
- · Very small samples (under 20)
- · Comparing many groups simultaneously
R + GGPLOT2 CODE EXAMPLE
ggplot2
ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 12, fill = "#ff6a00", color = "white") + labs(title = "Distribution of MPG", x = "MPG", y = "Count")
Run this code now
Paste the code above into RChat and see the histogram rendered instantly in your browser.
SIMILAR CHART TYPES
Density Plot geom_density()
Smoothed continuous curve estimating the probability distribution of a variable.Box Plot geom_boxplot()
Shows median, quartiles, range, and outliers as a compact distribution summary.Violin Plot geom_violin()
Combines box plot with kernel density, showing the full shape of the distribution.Ridgeline Plot geom_density_ridges()
Stacked overlapping density plots showing distribution changes across groups.ALTERNATIVES FOR YOUR DATA TYPE
Bar Chart Comparison, Ranking
Compares values across discrete categories using rectangular bars proportional to values.Horizontal Bar Chart Comparison, Ranking
Horizontal bars ideal for long labels, many categories, or ranked/sorted data.Grouped Bar Chart Comparison
Clusters of bars comparing sub-groups within each category side by side.