如何在循环中绘制许多回归的结果?

How to plot the results of many regressions in a loop?

我的代码中有一个 for 循环,它对 mtcars 数据集的每个变量运行回归,并给出 r 平方和 p 值。我如何绘制或可视化这些结果以比较变量并查看哪个变量最重要。以下是结果:

var          rsquared               pvalue
d2   cyl 0.726180005093805 6.11268714258098e-10
d3  disp  0.71834334048973  9.3803265373815e-10
d4    hp 0.602437341423934 1.78783525412108e-07
d5  drat 0.463995167985087 1.77623992875241e-05
d6    wt 0.752832793658264 1.29395870135053e-10
d7  qsec 0.175296320261013   0.0170819884965196
d8    vs 0.440947686116142 3.41593725441993e-05
d9    am 0.359798943425465 0.000285020743935068
d10 gear  0.23067344813203  0.00540094822470767
d11 carb  0.30351843705443  0.00108444622049167

在ggplot2中使用geom_text和颜色区分显着性

library(ggplot2) 
library(ggrepel)

ggplot(data, aes(x = pvalue, y = rsquared, label = var, color = pvalue<0.05)) + 
  geom_point(size = 1.5) +
  geom_text_repel(show.legend = FALSE) + 
  scale_color_manual(values = c("TRUE" = "blue", "FALSE" = "green"),
                     labels = c("TRUE" = "Significant", "FALSE" = "Insignificant")) +
  labs(color='Significance (p.value < 0.5)') +
  theme_classic()