Learn R Programming

daltoolbox (version 1.2.747)

plot_density_class: Plot density per class

Description

Kernel density plot grouped by a class label.

Usage

plot_density_class(
  data,
  class_label,
  label_x = "",
  label_y = "",
  colors = NULL,
  bin = NULL,
  alpha = 0.5
)

Value

returns a ggplot2::ggplot graphic

Arguments

data

data.frame with class label and a numeric column

class_label

name of the grouping (class) column

label_x

x‑axis label

label_y

y‑axis label

colors

optional vector of fills per class

bin

optional bin width passed to geom_density

alpha

fill transparency (0–1)

Details

Expects data with a grouping column named in class_label and one numeric column. Each group is filled with a distinct color (if provided).

Examples

Run this code
grf <- plot_density_class(iris |> dplyr::select(Sepal.Width, Species),
class = "Species", colors=c("red", "green", "blue"))
plot(grf)

Run the code above in your browser using DataLab