Slope_plots.R

lourymigliorelli — Oct 15, 2013, 6:07 PM

install.packages("ggplot2")
Error: trying to use CRAN without setting a mirror
require(ggplot2)
Loading required package: ggplot2
env <- read.csv("rs_env_plot.csv")
head(env)
         Study.Site NDVI.mean NDVI.CV Int.NDVI EVI.mean EVI.CV mean.sla.wt
1  Awaawapuhi Trail      0.81    7.23    182.9     0.38  12.41       8.649
2     Nualolo Trail      0.82    3.93    184.4     0.40  11.50      11.729
3     Milolii Ridge      0.79    8.05    179.8     0.40  13.71      12.489
4     Waimea Canyon      0.79   10.92    174.7     0.47  19.44      18.908
5       Honouliuli       0.80    9.62    178.3     0.47  21.05      28.624
6 Kaluakauila Gulch      0.66   17.75    149.2     0.43  28.95       8.825
  mean.sla.new sum.sla.wt mean.sla.wt.dom mean.sla.dom sum.sla.wt.dom
1        82.22      95.14          12.085        81.17         48.340
2        76.88      93.83          13.670        77.79         68.352
3        76.68      87.42          22.829        86.98         68.487
4        96.90     132.36           9.428        63.52         18.856
5        99.39     143.12           3.288        63.99          6.576
6        98.76      70.60          20.157        71.95         60.472
  mean.sub sum.sub sum.sub.wt Precip Temp Species.Richness Density
1    82.41   741.7      71.49   1823   21               21     245
2    75.57   453.4      71.08   1520   22               13     279
3    74.91   449.5      72.58   1314   20                9     313
4   100.38   501.9     114.15   1452   19               10     166
5    83.70   334.8     129.65   1020   21               12     161
6    85.17   596.2      69.95   1047   22               13     326
  Basal.Area Canopy.Height   NSR Substrate.Age      D common not.singleton
1        4.5          7.11  9.52           4.7 0.8871     98           175
2        6.3          8.37 15.38           4.7 0.8318    189           268
3        2.5          8.88 22.22           4.7 0.6793    227           275
4        3.8          9.82 60.00           4.7 0.7876      1           109
5        3.6          9.44 33.33           3.0 0.7085      4           148
6        2.1          5.98 46.15           3.0 0.4328    249           303
  pca.structure indiv    comp Evenness    H. Abun.Slope
1        1.1009   250 -0.8639   0.8142 2.479   -0.09163
2        2.4268   278 -0.7366   0.7860 2.016   -0.16200
3        0.9945   283 -0.9894   0.6881 1.512   -0.23000
4        0.9118   166 -0.3115   0.7691 1.771   -0.20930
5        0.7024   161  0.4703   0.6928 1.722   -0.14550
6        0.2292   326  0.1177   0.4168 1.069   -0.12439


mod = lm(env$Abun.Slope ~ env$Species.Richness)
modsum = summary(mod)
modsum

Call:
lm(formula = env$Abun.Slope ~ env$Species.Richness)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.14406 -0.02776  0.00658  0.03215  0.10169 

Coefficients:
                     Estimate Std. Error t value Pr(>|t|)    
(Intercept)          -0.40013    0.04512   -8.87  1.3e-06 ***
env$Species.Richness  0.01796    0.00411    4.37  0.00091 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.0647 on 12 degrees of freedom
Multiple R-squared:  0.614, Adjusted R-squared:  0.582 
F-statistic: 19.1 on 1 and 12 DF,  p-value: 0.000911
r2 = modsum$adj.r.squared
r2
[1] 0.5821
modsum$coefficients
                     Estimate Std. Error t value  Pr(>|t|)
(Intercept)          -0.40013   0.045115  -8.869 1.289e-06
env$Species.Richness  0.01796   0.004109   4.371 9.107e-04
my.p = modsum$coefficients[2,4]
my.p
[1] 0.0009107

ggplot(env, aes(x=env$Species.Richness, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("Species Richness") + geom_smooth(method = "lm", se = FALSE) + 
  annotate("text", label = "Adjusted R-squared = 0.58206", x = 15, y = 2) +
  annotate("text", label = "P-value = 0.00091", x = 15, y = 1.8) + 
  annotate("text", label = "S", x = 15, y = 1.6)

plot of chunk SlopePlots



lm(env$Abun.Slope ~ env$NDVI.mean)

Call:
lm(formula = env$Abun.Slope ~ env$NDVI.mean)

Coefficients:
  (Intercept)  env$NDVI.mean  
       -0.411          0.291  
lm(env$Abun.Slope ~ env$Substrate.Age)

Call:
lm(formula = env$Abun.Slope ~ env$Substrate.Age)

Coefficients:
      (Intercept)  env$Substrate.Age  
          -0.2659             0.0206  
lm(env$Abun.Slope ~ env$Precip)

Call:
lm(formula = env$Abun.Slope ~ env$Precip)

Coefficients:
(Intercept)   env$Precip  
  -0.401982     0.000169  
lm(env$Abun.Slope ~ env$Temp)

Call:
lm(formula = env$Abun.Slope ~ env$Temp)

Coefficients:
(Intercept)     env$Temp  
   -0.09553     -0.00599  

mod2 = lm(env$Abun.Slope ~ env$Substrate.Age)
mod2sum = summary(mod2)
mod2sum

Call:
lm(formula = env$Abun.Slope ~ env$Substrate.Age)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.2194 -0.0437  0.0293  0.0660  0.1153 

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
(Intercept)        -0.2659     0.0434   -6.13  5.1e-05 ***
env$Substrate.Age   0.0206     0.0149    1.38     0.19    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.0968 on 12 degrees of freedom
Multiple R-squared:  0.136, Adjusted R-squared:  0.0643 
F-statistic: 1.89 on 1 and 12 DF,  p-value: 0.194
r2 = mod2sum$adj.r.squared
r2
[1] 0.0643
mod2sum$coefficients
                  Estimate Std. Error t value  Pr(>|t|)
(Intercept)       -0.26587    0.04336  -6.132 5.085e-05
env$Substrate.Age  0.02057    0.01495   1.376 1.940e-01
my.p = mod2sum$coefficients[2,4]
my.p
[1] 0.194

ggplot(env, aes(x=env$Substrate.Age, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("Substrate Age") + geom_smooth(method = "lm", se = FALSE) +
  annotate("text", label = "Adjusted R-squared = 0.06430", x = 3, y = -0.36) +
  annotate("text", label = "P-value = 0.19397", x = 3, y = -0.38) + 
  annotate("text", label = "NS", x = 3, y = -0.4)

plot of chunk SlopePlots


mod3 = lm(env$Abun.Slope ~ env$Precip)
mod3sum = summary(mod3)
mod3sum

Call:
lm(formula = env$Abun.Slope ~ env$Precip)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.16073 -0.05166 -0.00685  0.07005  0.10271 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) -4.02e-01   7.51e-02   -5.35  0.00017 ***
env$Precip   1.69e-04   6.57e-05    2.57  0.02471 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.0837 on 12 degrees of freedom
Multiple R-squared:  0.354, Adjusted R-squared:  0.301 
F-statistic: 6.59 on 1 and 12 DF,  p-value: 0.0247
r2 = mod3sum$adj.r.squared
r2
[1] 0.3006
mod3sum$coefficients
              Estimate Std. Error t value  Pr(>|t|)
(Intercept) -0.4019816  7.510e-02  -5.353 0.0001729
env$Precip   0.0001687  6.574e-05   2.566 0.0247057
my.p = mod3sum$coefficients[2,4]
my.p
[1] 0.02471

ggplot(env, aes(x=env$Precip, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("Precipitation") + geom_smooth(method = "lm", se = FALSE) +
  annotate("text", label = "Adjusted R-squared = 0.30058", x = 1500, y = -0.36) +
  annotate("text", label = "P-value = 0.02471", x = 1500, y = -0.38) + 
  annotate("text", label = "S", x = 1500, y = -0.4)

plot of chunk SlopePlots


mod4 = lm(env$Abun.Slope ~ env$Temp)
mod4sum = summary(mod4)
mod4sum

Call:
lm(formula = env$Abun.Slope ~ env$Temp)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.2330 -0.0182  0.0182  0.0643  0.1298 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.09553    0.54103   -0.18     0.86
env$Temp    -0.00599    0.02645   -0.23     0.82

Residual standard error: 0.104 on 12 degrees of freedom
Multiple R-squared:  0.00426,   Adjusted R-squared:  -0.0787 
F-statistic: 0.0514 on 1 and 12 DF,  p-value: 0.825
r2 = mod4sum$adj.r.squared
r2
[1] -0.07872
mod4sum$coefficients
             Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.095528    0.54103 -0.1766   0.8628
env$Temp    -0.005994    0.02645 -0.2266   0.8245
my.p = mod4sum$coefficients[2,4]
my.p
[1] 0.8245

ggplot(env, aes(x=env$Temp, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("Temp") + geom_smooth(method = "lm", se = FALSE) +
  annotate("text", label = "Adjusted R-squared = -0.07872", x = 20, y = -0.36) +
  annotate("text", label = "P-value = 0.82453", x = 20, y = -0.38) + 
  annotate("text", label = "NS", x = 20, y = -0.4)

plot of chunk SlopePlots


mod5 = lm(env$Abun.Slope ~ env$NDVI.mean)
mod5sum = summary(mod5)
mod5sum

Call:
lm(formula = env$Abun.Slope ~ env$NDVI.mean)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.2387 -0.0323  0.0221  0.0593  0.0942 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)   
(Intercept)     -0.411      0.110   -3.72   0.0029 **
env$NDVI.mean    0.291      0.162    1.79   0.0983 . 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.0925 on 12 degrees of freedom
Multiple R-squared:  0.211, Adjusted R-squared:  0.145 
F-statistic: 3.21 on 1 and 12 DF,  p-value: 0.0983
r2 = mod5sum$adj.r.squared
r2
[1] 0.1454
mod5sum$coefficients
              Estimate Std. Error t value Pr(>|t|)
(Intercept)    -0.4106     0.1103  -3.723  0.00291
env$NDVI.mean   0.2910     0.1623   1.792  0.09830
my.p = mod5sum$coefficients[2,4]
my.p
[1] 0.0983

ggplot(env, aes(x=env$NDVI.mean, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("NDVI mean") + geom_smooth(method = "lm", se = FALSE) +
  annotate("text", label = "Adjusted R-squared = 0.14544", x = .45, y = -0.1) +
  annotate("text", label = "P-value = 0.09830", x = .45, y = -0.12) + 
  annotate("text", label = "NS", x = .45, y = -0.14)

plot of chunk SlopePlots


mod6 = lm(env$Abun.Slope ~ env$Basal.Area)
mod6sum = summary(mod6)
mod6sum

Call:
lm(formula = env$Abun.Slope ~ env$Basal.Area)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.2230 -0.0263  0.0127  0.0681  0.1111 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)     -0.2793     0.0623   -4.48  0.00075 ***
env$Basal.Area   0.0209     0.0192    1.09  0.29785    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.0993 on 12 degrees of freedom
Multiple R-squared:  0.0898,    Adjusted R-squared:  0.014 
F-statistic: 1.18 on 1 and 12 DF,  p-value: 0.298
r2 = mod6sum$adj.r.squared
r2
[1] 0.01398
mod6sum$coefficients
               Estimate Std. Error t value  Pr(>|t|)
(Intercept)    -0.27933    0.06231  -4.483 0.0007488
env$Basal.Area  0.02085    0.01916   1.088 0.2978452
my.p = mod6sum$coefficients[2,4]
my.p
[1] 0.2978

ggplot(env, aes(x=env$Basal.Area, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("Basal Area") + geom_smooth(method = "lm", se = FALSE) +
  annotate("text", label = "Adjusted R-squared = 0.01398", x = 5, y = -0.36) +
  annotate("text", label = "P-value = 0.29785", x = 5, y = -0.38) + 
  annotate("text", label = "NS", x = 5, y = -0.4)

plot of chunk SlopePlots


mod7 = lm(env$Abun.Slope ~ env$Density)
mod7sum = summary(mod7)
mod7sum

Call:
lm(formula = env$Abun.Slope ~ env$Density)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.2240 -0.0450  0.0239  0.0720  0.1082 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.267901   0.059910   -4.47  0.00076 ***
env$Density  0.000278   0.000298    0.93  0.36956    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.101 on 12 degrees of freedom
Multiple R-squared:  0.0675,    Adjusted R-squared:  -0.0102 
F-statistic: 0.869 on 1 and 12 DF,  p-value: 0.37
r2 = mod7sum$adj.r.squared
r2
[1] -0.01016
mod7sum$coefficients
              Estimate Std. Error t value  Pr(>|t|)
(Intercept) -0.2679005  0.0599099 -4.4717 0.0007634
env$Density  0.0002779  0.0002981  0.9323 0.3695553
my.p = mod7sum$coefficients[2,4]
my.p
[1] 0.3696

ggplot(env, aes(x=env$Density, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("Density") + geom_smooth(method = "lm", se = FALSE) +
  annotate("text", label = "Adjusted R-squared = -0.01016", x = 250, y = -0.36) +
  annotate("text", label = "P-value = 0.36956", x = 250, y = -0.38) + 
  annotate("text", label = "NS", x = 250, y = -0.4)

plot of chunk SlopePlots


mod8 = lm(env$Abun.Slope ~ env$Canopy.Height)
mod8sum = summary(mod8)
mod8sum

Call:
lm(formula = env$Abun.Slope ~ env$Canopy.Height)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.17038 -0.04675 -0.00383  0.06644  0.12798 

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
(Intercept)        -0.3669     0.0770   -4.76  0.00046 ***
env$Canopy.Height   0.0207     0.0102    2.03  0.06465 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.0898 on 12 degrees of freedom
Multiple R-squared:  0.256, Adjusted R-squared:  0.194 
F-statistic: 4.14 on 1 and 12 DF,  p-value: 0.0647
r2 = mod8sum$adj.r.squared
r2
[1] 0.1944
mod8sum$coefficients
                  Estimate Std. Error t value  Pr(>|t|)
(Intercept)       -0.36686    0.07702  -4.763 0.0004617
env$Canopy.Height  0.02071    0.01018   2.034 0.0646519
my.p = mod8sum$coefficients[2,4]
my.p
[1] 0.06465

ggplot(env, aes(x=env$Canopy.Height, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("Canopy Height") + geom_smooth(method = "lm", se = FALSE) +
  annotate("text", label = "Adjusted R-squared = 0.19444", x = 10, y = -0.36) +
  annotate("text", label = "P-value = 0.06465", x = 10, y = -0.38) + 
  annotate("text", label = "NS", x = 10, y = -0.4)

plot of chunk SlopePlots


mod9 = lm(env$Abun.Slope ~ env$NSR)
mod9sum = summary(mod9)
mod9sum

Call:
lm(formula = env$Abun.Slope ~ env$NSR)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.1526 -0.0378  0.0100  0.0602  0.1386 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)  
(Intercept) -0.13376    0.04704   -2.84    0.015 *
env$NSR     -0.00280    0.00135   -2.08    0.060 .
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.0893 on 12 degrees of freedom
Multiple R-squared:  0.264, Adjusted R-squared:  0.203 
F-statistic: 4.31 on 1 and 12 DF,  p-value: 0.0599
r2 = mod9sum$adj.r.squared
r2
[1] 0.2032
mod9sum$coefficients
             Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.133762   0.047044  -2.843  0.01481
env$NSR     -0.002801   0.001349  -2.077  0.05992
my.p = mod9sum$coefficients[2,4]
my.p
[1] 0.05992

ggplot(env, aes(x=env$NSR, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("NSR") + geom_smooth(method = "lm", se = FALSE) +
  annotate("text", label = "Adjusted R-squared = 0.20318", x = 20, y = -0.36) +
  annotate("text", label = "P-value = 0.05992", x = 20, y = -0.38) + 
  annotate("text", label = "NS", x = 20, y = -0.4)

plot of chunk SlopePlots


mod10 = lm(env$Abun.Slope ~ env$pca.structure)
mod10sum = summary(mod10)
mod10sum

Call:
lm(formula = env$Abun.Slope ~ env$pca.structure)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.19757 -0.04523  0.00576  0.07788  0.09858 

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
(Intercept)        -0.2180     0.0251   -8.70  1.6e-06 ***
env$pca.structure   0.0300     0.0180    1.67     0.12    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.0938 on 12 degrees of freedom
Multiple R-squared:  0.189, Adjusted R-squared:  0.121 
F-statistic: 2.79 on 1 and 12 DF,  p-value: 0.121
r2 = mod10sum$adj.r.squared
r2
[1] 0.1212
mod10sum$coefficients
                  Estimate Std. Error t value  Pr(>|t|)
(Intercept)       -0.21798    0.02506  -8.698 1.581e-06
env$pca.structure  0.03001    0.01796   1.671 1.205e-01
my.p = mod10sum$coefficients[2,4]
my.p
[1] 0.1205

ggplot(env, aes(x=env$pca.structure, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("pca.structure") + geom_smooth(method = "lm", se = FALSE) +
  annotate("text", label = "Adjusted R-squared = 0.12119", x = 1, y = -0.36) +
  annotate("text", label = "P-value = 0.12055", x = 1, y = -0.38) + 
  annotate("text", label = "NS", x = 1, y = -0.4)

plot of chunk SlopePlots


mod11 = lm(env$Abun.Slope ~ env$Evenness)
mod11sum = summary(mod11)
mod11sum

Call:
lm(formula = env$Abun.Slope ~ env$Evenness)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.2311 -0.0174  0.0226  0.0657  0.1364 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)
(Intercept)   -0.1717     0.1511   -1.14     0.28
env$Evenness  -0.0692     0.2221   -0.31     0.76

Residual standard error: 0.104 on 12 degrees of freedom
Multiple R-squared:  0.00802,   Adjusted R-squared:  -0.0746 
F-statistic: 0.0971 on 1 and 12 DF,  p-value: 0.761
r2 = mod11sum$adj.r.squared
r2
[1] -0.07464
mod11sum$coefficients
             Estimate Std. Error t value Pr(>|t|)
(Intercept)  -0.17169     0.1511 -1.1359   0.2782
env$Evenness -0.06921     0.2221 -0.3116   0.7607
my.p = mod11sum$coefficients[2,4]
my.p
[1] 0.7607

ggplot(env, aes(x=env$Evenness, y=Abun.Slope)) + 
  geom_point(col="red") + 
  ylab("Slope") + 
  xlab("Evenness") + geom_smooth(method = "lm", se = FALSE) +
  annotate("text", label = "Adjusted R-squared = -0.07464", x = 0.55, y = -0.36) +
  annotate("text", label = "P-value = 0.76072", x = 0.55, y = -0.38) + 
  annotate("text", label = "NS", x = 0.55, y = -0.4)

plot of chunk SlopePlots