Learn R Programming

daltoolbox (version 1.1.727)

plot_density: Plot density

Description

This function generates a density plot from a data frame containing numeric values using ggplot2. If the data frame has multiple columns, densities can be grouped and plotted.

Usage

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

Value

returns a ggplot graphic

Arguments

data

data.frame contain x, value, and variable

label_x

x-axis label

label_y

y-axis label

colors

color vector

bin

bin width for density estimation

alpha

level of transparency

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