> par(mai=c(0.6,0.6,0.4,0.4),cex=0.7)
> set.seed(2025)
> x<-rnorm(200)
> y<-1+2*x+rnorm(200
+ )
> d<-data.frame(x,y)
> plot(d,xlab="x=自变量",ylab="y=因变量")
> grid(col="grey60")
>axis(side=4,col.ticks="blue",lty=1)
> polygon(d[chull(d),],lty=6,lwd=1,col="lightgreen")
> points(d)
> points(mean(x),mean(y),pch=19,cex=5,col=2)
> abline(v=mean(x),h=mean(y),lty=2,col="grey30")
> abline(lm(y~x),lwd=2,col=2)
> lines(lowess(y~x,f=1/6),col=4,lwd=2,lty=6)
> segments(-0.8,0,-1.6,3.3,lty=6,col="blue")
> arrows(0.45,-2.2,-0.8,-0.6,code=2,angle=25,length=0.06,col=2)
> text(-2.2,3.5,labels=expression("拟合的曲线"),adj=c(-0.1,0.02),col=4)
> rect(0.4,-1.6,1.8,-3,col="pink",border = "grey60")
> mtext(e
2021-09-16 统计学——基于R(第四版)plot函数和一些低级绘图函数的使用
最新推荐文章于 2022-11-14 12:29:19 发布