# Basic usage with formula syntax (no grouping)
y <- rnorm(100)
plot_density(y)
# With grouping variable
group <- rep(c("A", "B", "C"), c(30, 40, 30))
plot_density(y ~ group)
# With custom colors (scalar - same for all)
plot_density(y ~ group, col = "blue")
# With custom colors (vector - different for each group)
plot_density(y ~ group, col = c("red", "green", "blue"))
# Multiple parameters
plot_density(y ~ group, col = c("red", "green", "blue"), lwd = c(1, 2, 3))
# With line type
plot_density(y ~ group, col = c("red", "green", "blue"), lty = c(1, 2, 3), lwd = 2)
# Using data frame
df <- data.frame(value = rnorm(100), group = rep(c("A", "B"), 50))
plot_density(value ~ group, data = df)
plot_density(value ~ group, data = df, col = c("red", "blue"))
# Compare two vectors
y1 <- rnorm(50)
y2 <- rnorm(50, mean = 1)
plot_density(y1, y2)
Run the code above in your browser using DataLab