绘制一系列具有不同参数的 pdf 和 cdfs

问题描述

我希望在 R 中重现类似于 this image 的东西。我的目标是在瑞利和其他具有不同参数的分布的同一图上绘制一系列 pdf 和/或 cdfs。理想情况下,我想将相同的 x 值序列以及一系列参数值强制转换为数据框,然后使用 ggplot 绘制该数据框。

到目前为止,我已经尝试了以下几种排列:

"Scale

解决这个问题的最佳方法是什么?我已经使用 for 循环和 rep(seq(...)) 做了一些尝试,但没有成功。谢谢。

解决方法

具有尺度参数 $\sigma,$ 的瑞利分布有 密度函数 $f(x) = \frac{x}{\sigma^2}\exp\left[-.5(\frac{x^2}{\sigma^2 })\right],$ for $x,\sigma > 0.$ 如果在 R 的基数中绘制密度函数,则 根据需要使用 dnormdgamma 等。 [过程curve需要一个 x 中的参数。]

m = 5;  sg = c(.5,1,2,3,4)
frb=c("blue","darkgreen","red","cyan4","purple")
hdr="Densities of Rayleigh Distributions: Scale = 0.5,4"
plot(c(0,11),c(0,1.2),col="white",ylab="Density",xlab="x",main=hdr)
 abline(h=0,col="grey");  abline(v=0,col="grey")
for(i in 1:m) {
 curve((x/sg[i]^2)*exp(-.5*(x^2/sg[i]^2)),add=T,col=frb[i])
 }

enter image description here