init
This commit is contained in:
24
src/test-plot.R
Normal file
24
src/test-plot.R
Normal file
@@ -0,0 +1,24 @@
|
||||
# 设置随机种子以便重现
|
||||
set.seed(123)
|
||||
|
||||
# 生成示例数据
|
||||
x <- rnorm(100) # 生成 100 个正态分布随机数作为 x 值
|
||||
y <- rnorm(100) # 生成 100 个正态分布随机数作为 y 值
|
||||
|
||||
# 创建散点图
|
||||
plot(x, y,
|
||||
main = "Scatter Plot of Random Data", # 图表标题
|
||||
xlab = "X-axis Label", # X 轴标签
|
||||
ylab = "Y-axis Label", # Y 轴标签
|
||||
col = "blue", # 点的颜色
|
||||
pch = 19
|
||||
) # 点的形状
|
||||
|
||||
# 添加回归线
|
||||
abline(lm(y ~ x), col = "red") # 添加线性回归线,红色
|
||||
|
||||
# 添加图例
|
||||
legend("topright",
|
||||
legend = c("Data Points", "Regression Line"),
|
||||
col = c("blue", "red"), pch = c(19, NA), lty = c(NA, 1)
|
||||
)
|
Reference in New Issue
Block a user