0
我想添加一个图例ggplot区分模拟的正态分布和生成一个。下面是我的代码当使用stat_function添加图例ggplot
set.seed(1)
lambda = .2
n = 40
sim = 10000
means = replicate(sim, expr = mean(rexp(n,lambda)))
ggplot(data.frame(means), aes(x=means)) +
geom_density() +
stat_function(fun = dnorm, color = "blue",
arg = list(mean = 1/lambda, sd=sqrt(lambda^-2/n))) +
scale_colour_manual("Legend title", values = c("red", "blue"))
我尝试使用scale_colour_manual给出另一个答案计算器,但我不能让一个传奇展现出来。
参考答案 Using legend with stat_function in ggplot2