R语言简单的图像制作(基本参数演示)

图形展示

在这里插入图片描述

代码展示

library(showtext)
showtext_auto()
par(mai = c(0.6,0.6,0.4,0.4),cex = 0.7)
set.seed(2)
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(expression(hat(y)==hat(beta)[0]+hat(beta)[1]*x),cex = 0.9,side = 1,line = -3.5,adj = 0.8)
legend("topleft",inset = 0.02,legend = c("拟合直线", "拟合曲线"),
       col = c(2,4), cex = 0.8,fill = c("red","blue"),box.col = "grey60",ncol = 1,
       lty = c(1, 6), pch = c(9,8),bg = "snow3",text.width = 0.6)
title("散点图及拟合直线和曲线 \n 并为图形增加新的元素",cex.main = 1,font.main = 4)
box(col = 4,lwd = 2)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

玩转数据

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值