简体   繁体   English

用两个密度函数绘制R中的密度曲线

[英]Plot density curve in R with two density functions

I am struggling to create a continuous density curve in R for the below pdf: 我正在努力为以下pdf创建R中的连续密度曲线:

{ 3x(1-x)^2     0 < x < 1

f(x) = { 3(2-x)(1-x)^2  1 ≤ x  < 2

{ 0              otherwise

Using the curve function, I can plot the two functions separately but not together: 使用曲线函数,我可以分别绘制两个函数,但不能一起绘制:

curve(3*x*(1-x)^2,0,1)

curve(3*(2-x)*(1-x)^2,1,2)

Any help would be appreciated? 任何帮助,将不胜感激?

You can start with an empty graph and then put together these pieces with add=TRUE . 您可以从一个图开始,然后使用add=TRUE将这些片段放在一起。

plot(NULL, xlim=c(0,2), ylim=c(0,0.5))
curve(3*x*(1-x)^2,0,1, add=TRUE)
curve(3*(2-x)*(1-x)^2,1,2, add=TRUE)

两条曲线

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM