powered by
Kernel density plot grouped by a class label.
plot_density_class( data, class_label, label_x = "", label_y = "", colors = NULL, bin = NULL, alpha = 0.5 )
returns a ggplot2::ggplot graphic
data.frame with class label and a numeric column
name of the grouping (class) column
x‑axis label
y‑axis label
optional vector of fills per class
optional bin width passed to geom_density
geom_density
fill transparency (0–1)
Expects data with a grouping column named in class_label and one numeric column. Each group is filled with a distinct color (if provided).
data
class_label
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