Distribution Numerical
Density Plot
ggplot2: geom_density() · Package: ggplot2 · Variables: 1 numerical, 1-4 groups
WHAT IS A DENSITY PLOT?
A density plot (also called a kernel density estimate or KDE) is a smoothed, continuous version of a histogram. Instead of discrete bins, it shows a smooth curve representing the estimated probability distribution. Density plots shine when comparing 2-4 groups on the same axes — overlapping semi-transparent density curves make it easy to see how distributions differ. They avoid the bin-width sensitivity of histograms. In ggplot2, use geom_density() with an alpha parameter for transparency when overlaying multiple groups.
BEST FOR
- · Comparing 2-4 distribution shapes
- · Smoother alternative to histogram
- · Continuous data shape analysis
AVOID WHEN
- · Discrete/categorical data
- · Very small samples
- · When exact bin counts matter
R + GGPLOT2 CODE EXAMPLE
ggplot2
ggplot(mtcars, aes(x = mpg, fill = factor(cyl))) + geom_density(alpha = 0.5) + labs(title = "MPG Density by Cylinders", x = "MPG", fill = "Cylinders")
Run this code now
Paste the code above into RChat and see the density plot rendered instantly in your browser.
SIMILAR CHART TYPES
Histogram geom_histogram()
Frequency distribution of a continuous variable grouped into bins, showing distribution shape.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.