> library(ggplot2) > library(ggpubr) > > # 创建一个示例数据集 > predicted <- c(17.65138, 25.20848, 35.84161, 43.60831, 49.49514, 53.97651, 57.38967, 66.16531) > actual <- c(14.6313, 20.18572, 28.97064, 35.23582, 40.41306, 44.54261, 47.12309, 69.51883) > data <- data.frame(predicted, actual) > > # 计算相关系数 R2 > r2 <- cor(predicted, actual)^2 > > # 绘制拟合图并添加相关系数 R2 > ggplot(data, aes(x=predicted, y=actual)) + + geom_point() + + geom_smooth(method="lm", se=FALSE) + + stat_cor(label = paste0("R2 = ", round(r2, 2)), + label.x = 3, label.y = 4.5) + + labs(title="Predicted vs Actual", x="Predicted", y="Actual") Error in stat_cor(label = paste0("R2 = ", round(r2, 2)), label.x = 3, : 参数1有多个与之相对应的正式参数