1、在intellij idea中使用R语言plot函数时,会遇到各种各样的问题,会出现图片不显示问题,
可以看到,目前我电脑r语言版本为4.2.1,输入下面代码:
# # 安装包
# install.packages('ggplot2')
# library(ggplot2)
Sys.setlocale(category = 'LC_ALL', locale = 'English_United States.1252')
# Sys.setlocale("LC_ALL","Chinese")
x <- c(18, 20, 22, 24, 26, 28, 30)
y <- c(26.86, 28.35, 28.87,28.75, 29.75, 30, 30.36)
model <- lm(y ~ x)
summary(model)
# 画出散点图
plot(x, y, pch = 19, col = "blue", cex = 2, xlab = "x", ylab = "y")# 绘图代码
# 画出拟合直线
plot(model)
# # 画出残差图
# plot(model, which = 1)
# # 画出标准化残差图
# plot(model, which = 2)
# # 画出QQ图
# plot(model, which = 3)
# # 画出方差-拟合值图
# plot(model, which = 4)
# # 画出学生化残差图
# plot(model, which = 5)
# # 画出Cook距离图
# plot(model, which = 6)
# 预测
predict(model, data.frame(x = 40))
# 置信区间
predict(model, data.frame(x = c(40)), interval = "confidence")
# 预测区间
predict(model, data.frame(x = c(40)), interval = "prediction")
# install.packages('lifecycle')
#
# options(repos="http://cran.rstudio.com/")
# install.packages("lifecycle", dependencies=TRUE)
# Install release version from CRAN
# install.packages("lifecycle")
#
# # Install development version from GitHub
# pak::pak("r-lib/lifecycle")
发现在R plot窗口没有图片生成:
这让我特别苦恼,在查阅了大量相关资料后,发现安装R语言版本为4.0.5后,问题得到了解决:
https://www.r-project.org/
https://cloud.r-project.org/
https://cloud.r-project.org/https://cloud.r-project.org/
在这里下载r4.0.5
安装完成后,问题得到了解决:
可以看到图形正常显示了。