gpt4 book ai didi

r - 如何在R中两个图表的顶部和中间添加标题

转载 作者:行者123 更新时间:2023-12-01 16:19:59 24 4
gpt4 key购买 nike

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")

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

enter image description here

我怎样才能做到这一点?

最佳答案

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

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

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)

将它们与夹在中间的代码放在一起,可以得到如下图:

enter image description here

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com