Learn R Programming

daltoolbox (version 1.2.747)

plot_density: Plot density

Description

Kernel density plot for one or multiple numeric columns.

Usage

plot_density(
  data,
  label_x = "",
  label_y = "",
  colors = NULL,
  bin = NULL,
  alpha = 0.25
)

Value

returns a ggplot2::ggplot graphic

Arguments

data

data.frame with one or more numeric columns

label_x

x‑axis label

label_y

y‑axis label

colors

optional fill color (single column) or vector for groups

bin

optional bin width passed to geom_density

alpha

fill transparency (0–1)

Details

If data has multiple numeric columns, densities are overlaid and filled by column (group). When a single column is provided, colors (if set) is used as a constant fill. The bin argument is passed to geom_density(binwidth=...).

Examples

Run this code
grf <- plot_density(iris |> dplyr::select(Sepal.Width), colors="blue")
plot(grf)

Run the code above in your browser using DataLab