R代码:
windows(width=9, height=6)
par(mfrow=c(1,2))
curve(dweibull(x,1,.5),from=0,to=4,col="blue",xlab="t",ylab="f(t)",main="Probability density function")
curve(dweibull(x,1.5,1),add=TRUE,col="red")
curve(dweibull(x,3,1),add=T,col="green")
text(3.5,2,expression(beta==.5),col="blue")
text(3.5,1.88,expression(beta==1.5),col="red")
text(3.5,1.76,expression(beta==3),col="green")
ht=function(x,lambda,beta){
h=lambda*beta*(lambda*x)^(beta-1)
return(h)
}
curve(ht(x,1,.5),xlim=c(0,4),ylim=c(0,4),xlab="t",ylab="f(t)",col="blue",main="Hazard function")
curve(ht(x,1,1.5),add=T,col="red")
curve(ht(x,1,3),add=T,col="green")
text(3.5,4,expression(beta==.5),col="blue")
text(3.5,3.85,expression(beta==1.5),col="red")
text(3.5,3.70,expression(beta==3),col="green")
Run Code Online (Sandbox Code Playgroud)

我想在两个图的顶部和中间编写“ Weibull分布”,如下所示:

我怎样才能做到这一点 ?
您需要对代码进行两个结合的修改。
首先使用以下命令设置oma(“ outer margin”)参数为标题保留一些空间par()
windows(width=9, height=6)
par(mfrow=c(1,2), oma=c(0,0,2,0))
Run Code Online (Sandbox Code Playgroud)
然后,要实际编写标题,请调用mtext(),设置outer=TRUE:
mtext("Weibull distribution", line=0, side=3, outer=TRUE, cex=2)
Run Code Online (Sandbox Code Playgroud)
将它们与夹在中间的代码放在一起,可以得到如下图:
