如何在r

时间:2018-09-13 07:07:37

标签: r ggplot2

o<-read.csv("old.csv')

Callosal_FA CST_FA  SLF_FA  Area_SMA_A
0.556566554 0.539971971 0.482016736 -0.007984
0.586793895 0.554954237 0.487595985 0.05567
0.613107046 0.597039029 0.467378312 0.136
0.59241945  0.58101919  0.460784717 0.03253
0.586344082 0.555524562 0.479480255 -0.01629
0.607088378 0.56048251  0.478998182 0.07981
0.595145661 0.571902322 0.461452732 0.07882
0.591501695 0.581156582 0.51408736  0.1143
0.587255765 0.566562088 0.462376015 0.1717
0.583943048 0.571209263 0.46400787  -0.01861
0.603512157 0.587332337 0.477376739 0.05672
0.582126533 0.565946603 0.459743433 0.002831
0.570966197 0.556258709 0.470341615 -0.003823
0.570307147 0.542675924 0.504833121 0.01764
0.579498276 0.569837284 0.475364742 -0.000387
0.570543729 0.542095809 0.468923119 0.117
0.613672747 0.572339549 0.486481493 0.1264
0.570649037 0.554125163 0.522845609 0.04696
0.580601176 0.558799894 0.504017998 0.1056
0.576166024 0.542110191 0.476548484 0.05783
0.579598762 0.546776236 0.491528835 0.08022
0.604775228 0.576144869 0.506060596 0.1515
0.555354582 0.556518053 0.492985322 -0.01114
0.580857907 0.556575944 0.484096309 0.03578

我想绘制多个组的回归模型结果(r平方)。 我已经尝试过这一步,并设法为一组做。

 y <- lm(o$Area_SMA_A ~ o$CST_FA + o$SLF_FA + o$Callosal_FA)

然后使用以下代码:

library(ggplot2)
  ggplot(y$model, aes_string(x = names(y$model)[2], y = names(y$model)[1])) + 
     geom_point() + 
     stat_smooth(method = "lm", col = "lightblue") + 
     labs(title = paste("Adj R2 = ",signif(summary(y)$adj.r.squared, 5), 
                        "Intercept =",signif(y$coef[[1]],5 ), 
                        " Slope =",signif(y$coef[[2]], 5), 
                        " P =",signif(summary(y)$coef[2,4], 5)))

我制作了这张我想要的图像。

enter image description here

因为我有三组,所以我想为这两组添加另一个回归模型。有办法吗?谢谢。

m <- read.csv("middle.csv')

Callosal_FA CST_FA  SLF_FA  Area_SMA_A
0.599350895 0.59082334  0.518316923 0.04286
0.591540991 0.585592011 0.517415822 0.1291
0.62120411  0.613751115 0.456966929 0.05915
0.59344635  0.571179365 0.500941682 0.01122
0.621645795 0.599144316 0.487736421 0.0471
0.611521291 0.596407776 0.508636999 -0.08177
0.561589532 0.549150165 0.509993364 -0.002053
0.608089072 0.581477369 0.496346462 0.1157
0.583942196 0.576979247 0.505747697 0.01913
0.614675486 0.584447311 0.513085904 0.006673
0.599312499 0.585156336 0.475447955 0.05582
0.591977354 0.578031977 0.505042846 0.08293
0.602347244 0.582916321 0.504538196 -0.07645
0.628674145 0.595462642 0.469785878 0.04787
0.595963981 0.547983665 0.497874226 0.1132
0.604934306 0.586583356 0.502788492 0.08803
0.599656344 0.580235613 0.471793292 0.0118
0.587288357 0.559298093 0.535857414 0.06225
0.586031623 0.582565008 0.475876222 0.282
0.58277546  0.555852007 0.497386116 0.05266

y <- read.csv("young.csv')

Callosal_FA CST_FA  SLF_FA  Area_SMA_A
0.641939581 0.610050256 0.497039292 -0.05461
0.600969207 0.581011925 0.486918544 0.03801
0.597728695 0.569094851 0.522076721 0.08515
0.605851215 0.575788238 0.522207993 0.001711
0.615141198 0.586422768 0.49536629  0.08908
0.664600517 0.636086957 0.50723616  0.04712
0.617076761 0.577625164 0.50950881  0.02169
0.612482041 0.569112478 0.512551218 0.04043
0.627284885 0.597122461 0.541768958 0.003275
0.627408656 0.607896037 0.505038914 0.06681
0.609205487 0.577178474 0.508818934 -0.04759
0.606824376 0.593485569 0.530833127 0.05503
0.608929339 0.583816742 0.506553103 0.08804
0.623125338 0.599054187 0.518118823 0.04499
0.606161965 0.578010045 0.491883074 0.1487
0.605391626 0.585302201 0.488368677 0.1316
0.640007128 0.599344654 0.503622583 0.1909
0.598483618 0.588507596 0.508622188 0.2013
0.625079582 0.597286968 0.510829857 0.09116
0.620938861 0.577980188 0.52410613  0.02284
0.615765316 0.577922653 0.542867003 0.08179
0.606476852 0.571277288 0.486362068 0.2072
0.607761045 0.585516175 0.509739355 0.075
0.633673687 0.615854958 0.470963903 0.02209
0.641553411 0.621000635 0.492999164 0.101
0.588310547 0.57312727  0.490874808 0.07214
0.588535558 0.571499503 -0.08068    -0.03153

0 个答案:

没有答案