Get Started →
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.

Try RChat Free →

SIMILAR CHART TYPES

ALTERNATIVES FOR YOUR DATA TYPE