线性拟合
画图+拟合+拟合线
plot(x = wp$Europe,y = wp$Asia,pch=19)
m <- lm(wp$Asia~wp$Europe)
abline(m,col='blue',lty=1)
coef(m)
summary(m)$r.squared
加标注
legend('bottomright',
legend = c('Data','Linear fit'),
pch = c(19,NA),
lty = c(NA,1),
col = c('black','blue'),
bty = 'n')
加公式
eq <- substitute(italic(y) == b+a*italic(x)*","~italic(R)^2==r2,
list(b = format(coef(m)[1], digits = 2),
a = format(coef(m)[2], digits = 2),
r2 = format(summary(m)$r.squared, digits = 3)))
text(x=30000,y = 8500,labels = as.expression(eq),col = 'blue')
网友评论