This question already has an answer here:
Multi-panel titles in R

(1 个回答)


6年前关闭。




代码:
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")

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

我怎样才能做到这一点 ?

最佳答案

您需要对代码进行两次耦合修改。

首先通过使用 oma 设置 par()(“外边距”)参数为标题保留一些空间

windows(width=9, height=6)
par(mfrow=c(1,2), oma=c(0,0,2,0))

然后,要实际编写标题,请调用 mtext() ,设置 outer=TRUE :
mtext("Weibull distribution", line=0, side=3, outer=TRUE, cex=2)

将它们与夹在中间的代码放在一起会给你一个这样的情节:

关于r - 如何在R中的两个图形的顶部和中间添加标题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28010700/

10-12 17:44
查看更多