【发布时间】:2019-11-07 19:38:29
【问题描述】:
我使用 ggplot2 绘制密度曲线。绘制数据后,我想在其顶部添加一个正态密度图并进行填充。
目前,我正在使用 rnorm() 创建数据,但这效率不高,并且在小型数据集上效果不佳。
library(tidyverse)
#my data that I want to plot
my.data = rnorm(1000, 3, 10)
#create the normal density plot to overlay the data
overlay.normal = rnorm(1000, 0, 5)
all = tibble(my.data = my.data, overlay.normal = overlay.normal)
all = melt(all)
ggplot(all, aes(value, fill = variable))+geom_density()
目标是绘制我的数据并在其上覆盖正态分布(使用填充)。比如:
ggplot(my.data)+geom_density()+add_normal_distribution(mean = 0, sd = 5, fill = "red)
【问题讨论】:
-
你的问题到底是什么?
-
我在底部的问题中进行了编辑。