我想使用ggplot2不同的颜色和图例在一个图中创建多个核密度图。我是通过以下方式完成的:
library(tidyverse)
set.seed(1234)
x <- rnorm(25)
x %>% tibble() %>% ggplot(aes(x = values)) +
stat_density(aes(x, color = "0.1"), position = "identity", geom = "line",
kernel = "gaussian", bw = 0.1) +
stat_density(aes(x, color = "0.2236"), position = "identity", geom = "line",
kernel = "gaussian", bw = 0.2236) +
stat_density(aes(x, color = "0.334"), position = "identity", geom = "line",
kernel = "gaussian", bw = 0.334) +
stat_density(aes(x, color = "0.578"), position = "identity", geom = "line",
kernel = "gaussian", …Run Code Online (Sandbox Code Playgroud)