For your homework, we will use a sample plant diversity dataset to assess diversity called:

ENVS286_plant_abundance_SP17.csv

This dataset is measuring plant abundance for twelve grassland plots in Kansas. There are three habitat types (A, B, and C). You should have all the tools at your disposal from this lab (and previous labs) to answer the questions.

Q1: Why can’t you just feed the plant abundance data set into the vegan package functions directly?

#We can just feed our data set into the *vegan* because te format will not be reconigzed. So we need to transforman our data in the format vegan expects to be in.

Q2: Present the entire code that you would use to create a data frame with the three diversity indices for the plant abundance data.

plant_abundance<-read.csv("/Users/Amilian/Desktop/Copy of ENVS286_plant_abundance_SP17(2).csv")
summary (plant_abundance) #view imprted data sheet
##     Habitat  Achillea_millefolium Allium_textile Amelanchier_alnifolia
##  A1     :1   Min.   :10.00        Min.   :10     Min.   :10           
##  A2     :1   1st Qu.:30.00        1st Qu.:10     1st Qu.:10           
##  A3     :1   Median :35.00        Median :10     Median :10           
##  A4     :1   Mean   :33.33        Mean   :12     Mean   :10           
##  B1     :1   3rd Qu.:40.00        3rd Qu.:10     3rd Qu.:10           
##  B2     :1   Max.   :50.00        Max.   :20     Max.   :10           
##  (Other):6   NA's   :6            NA's   :7      NA's   :9            
##  Androsace_occidentalis Anemone_patens  Antennaria_neglecta
##  Min.   :10             Min.   :10.00   Min.   :20         
##  1st Qu.:10             1st Qu.:15.00   1st Qu.:20         
##  Median :20             Median :20.00   Median :20         
##  Mean   :30             Mean   :16.67   Mean   :20         
##  3rd Qu.:40             3rd Qu.:20.00   3rd Qu.:20         
##  Max.   :70             Max.   :20.00   Max.   :20         
##  NA's   :7              NA's   :9       NA's   :11         
##  Antennaria_parvifolia Arnica_fulgens Artemisia_cana Artemisia_frigida
##  Min.   :10.0          Min.   :30     Min.   :10.0   Min.   :20.00    
##  1st Qu.:12.5          1st Qu.:30     1st Qu.:10.0   1st Qu.:30.00    
##  Median :15.0          Median :30     Median :10.0   Median :50.00    
##  Mean   :15.0          Mean   :30     Mean   :12.5   Mean   :42.86    
##  3rd Qu.:17.5          3rd Qu.:30     3rd Qu.:12.5   3rd Qu.:55.00    
##  Max.   :20.0          Max.   :30     Max.   :20.0   Max.   :60.00    
##  NA's   :10            NA's   :11     NA's   :8      NA's   :5        
##  Artemisia_ludoviciana Aster_ericoides Aster_falcatus  Aster_laevis  
##  Min.   :20.0          Min.   :10      Min.   :20     Min.   :20.00  
##  1st Qu.:27.5          1st Qu.:10      1st Qu.:20     1st Qu.:45.00  
##  Median :40.0          Median :10      Median :20     Median :70.00  
##  Mean   :42.5          Mean   :10      Mean   :22     Mean   :53.33  
##  3rd Qu.:55.0          3rd Qu.:10      3rd Qu.:20     3rd Qu.:70.00  
##  Max.   :70.0          Max.   :10      Max.   :30     Max.   :70.00  
##  NA's   :8             NA's   :9       NA's   :7      NA's   :9      
##  Astragalus_aboriginum Astragalus_bisulcatus Astragalus_dasyglottis
##  Min.   :20            Min.   :10            Min.   :20.0          
##  1st Qu.:20            1st Qu.:10            1st Qu.:22.5          
##  Median :20            Median :10            Median :25.0          
##  Mean   :20            Mean   :10            Mean   :25.0          
##  3rd Qu.:20            3rd Qu.:10            3rd Qu.:27.5          
##  Max.   :20            Max.   :10            Max.   :30.0          
##  NA's   :11            NA's   :11            NA's   :10            
##  Bouteloua_gracilis Bromus_inermis Campanula_rotundifolia Carex_filifolia 
##  Min.   : 10.0      Min.   :10     Min.   :10.00          Min.   : 30.00  
##  1st Qu.: 67.5      1st Qu.:10     1st Qu.:10.00          1st Qu.: 65.00  
##  Median : 70.0      Median :10     Median :10.00          Median : 85.00  
##  Mean   : 70.0      Mean   :10     Mean   :16.67          Mean   : 76.67  
##  3rd Qu.: 90.0      3rd Qu.:10     3rd Qu.:20.00          3rd Qu.: 97.50  
##  Max.   :100.0      Max.   :10     Max.   :30.00          Max.   :100.00  
##  NA's   :4          NA's   :11     NA's   :9              NA's   :6       
##  Carex_obtusata   Cerastium_arvense Chenopodium_album Comandra_umbellata
##  Min.   : 50.00   Min.   :10        Min.   :20.0      Min.   :10        
##  1st Qu.: 70.00   1st Qu.:15        1st Qu.:42.5      1st Qu.:40        
##  Median : 85.00   Median :20        Median :55.0      Median :60        
##  Mean   : 81.67   Mean   :20        Mean   :47.5      Mean   :52        
##  3rd Qu.:100.00   3rd Qu.:25        3rd Qu.:60.0      3rd Qu.:70        
##  Max.   :100.00   Max.   :30        Max.   :60.0      Max.   :80        
##  NA's   :6        NA's   :9         NA's   :8         NA's   :7         
##  Descurainia_sophia Draba_nemorosa Elaeagnus_commutata Elymus_lanceolatus
##  Min.   :10         Min.   :10     Min.   :20          Min.   :10.00     
##  1st Qu.:10         1st Qu.:15     1st Qu.:20          1st Qu.:10.00     
##  Median :10         Median :20     Median :20          Median :30.00     
##  Mean   :10         Mean   :20     Mean   :20          Mean   :34.55     
##  3rd Qu.:10         3rd Qu.:25     3rd Qu.:20          3rd Qu.:50.00     
##  Max.   :10         Max.   :30     Max.   :20          Max.   :90.00     
##  NA's   :11         NA's   :9      NA's   :11          NA's   :1         
##  Elytrigia_repens Erigeron_glabellus Erigeron_pumilus
##  Min.   :20.0     Min.   :30         Min.   :20      
##  1st Qu.:27.5     1st Qu.:30         1st Qu.:20      
##  Median :35.0     Median :30         Median :20      
##  Mean   :35.0     Mean   :30         Mean   :20      
##  3rd Qu.:42.5     3rd Qu.:30         3rd Qu.:20      
##  Max.   :50.0     Max.   :30         Max.   :20      
##  NA's   :10       NA's   :11         NA's   :11      
##  Erysimum_inconspicuum Eurotia_lanata Festuca_hallii   Galium_boreale
##  Min.   :20            Min.   :10     Min.   : 30.00   Min.   : 30   
##  1st Qu.:20            1st Qu.:15     1st Qu.: 40.00   1st Qu.: 30   
##  Median :20            Median :20     Median : 75.00   Median : 40   
##  Mean   :20            Mean   :20     Mean   : 68.33   Mean   : 50   
##  3rd Qu.:20            3rd Qu.:25     3rd Qu.: 95.00   3rd Qu.: 50   
##  Max.   :20            Max.   :30     Max.   :100.00   Max.   :100   
##  NA's   :11            NA's   :9      NA's   :6        NA's   :7     
##  Gutierrezia_sarothrae Haplopappus_spinulosus Heterotheca_villosa
##  Min.   :10            Min.   :10             Min.   :10         
##  1st Qu.:10            1st Qu.:10             1st Qu.:10         
##  Median :10            Median :10             Median :10         
##  Mean   :10            Mean   :10             Mean   :10         
##  3rd Qu.:10            3rd Qu.:10             3rd Qu.:10         
##  Max.   :10            Max.   :10             Max.   :10         
##  NA's   :11            NA's   :11             NA's   :11         
##  Heuchera_richardsonii Hymenoxys_richardsonii Koeleria_macrantha
##  Min.   :10            Min.   :10             Min.   :10.00     
##  1st Qu.:10            1st Qu.:10             1st Qu.:30.00     
##  Median :10            Median :10             Median :40.00     
##  Mean   :10            Mean   :10             Mean   :53.33     
##  3rd Qu.:10            3rd Qu.:10             3rd Qu.:80.00     
##  Max.   :10            Max.   :10             Max.   :90.00     
##  NA's   :11            NA's   :11             NA's   :3         
##  Lactuca_pulchella Lathyrus_venosus Lepidium_densiflorum
##  Min.   :10.0      Min.   :10       Min.   :10          
##  1st Qu.:17.5      1st Qu.:10       1st Qu.:10          
##  Median :25.0      Median :10       Median :10          
##  Mean   :32.5      Mean   :10       Mean   :10          
##  3rd Qu.:40.0      3rd Qu.:10       3rd Qu.:10          
##  Max.   :70.0      Max.   :10       Max.   :10          
##  NA's   :8         NA's   :11       NA's   :11          
##  Musineon_divaricatum Oxytropis_sericea Penstemon_confertus
##  Min.   :20           Min.   :10        Min.   :10         
##  1st Qu.:20           1st Qu.:15        1st Qu.:10         
##  Median :20           Median :20        Median :10         
##  Mean   :20           Mean   :20        Mean   :10         
##  3rd Qu.:20           3rd Qu.:25        3rd Qu.:10         
##  Max.   :20           Max.   :30        Max.   :10         
##  NA's   :10           NA's   :10        NA's   :11         
##  Penstemon_nitidus Penstemon_procerus Petalostemon_purpureum
##  Min.   :10        Min.   :10         Min.   :40            
##  1st Qu.:10        1st Qu.:10         1st Qu.:40            
##  Median :10        Median :10         Median :40            
##  Mean   :10        Mean   :10         Mean   :40            
##  3rd Qu.:10        3rd Qu.:10         3rd Qu.:40            
##  Max.   :10        Max.   :10         Max.   :40            
##  NA's   :11        NA's   :11         NA's   :11            
##   Phlox_hoodii   Plantago_patagonica  Poa_cusickii   Poa_pratensis
##  Min.   :30.00   Min.   :20.00       Min.   :10.00   Min.   : 10  
##  1st Qu.:40.00   1st Qu.:25.00       1st Qu.:15.00   1st Qu.: 60  
##  Median :50.00   Median :30.00       Median :20.00   Median : 60  
##  Mean   :46.67   Mean   :33.33       Mean   :36.67   Mean   : 65  
##  3rd Qu.:55.00   3rd Qu.:40.00       3rd Qu.:50.00   3rd Qu.: 90  
##  Max.   :60.00   Max.   :50.00       Max.   :80.00   Max.   :100  
##  NA's   :9       NA's   :9           NA's   :9       NA's   :6    
##  Poa_sandbergii Potentilla_arguta Rosa_arkansana  Solidago_missouriensis
##  Min.   : 30    Min.   :10        Min.   :20.00   Min.   :10            
##  1st Qu.: 50    1st Qu.:10        1st Qu.:22.50   1st Qu.:15            
##  Median : 70    Median :10        Median :35.00   Median :20            
##  Mean   : 66    Mean   :10        Mean   :41.67   Mean   :30            
##  3rd Qu.: 80    3rd Qu.:10        3rd Qu.:55.00   3rd Qu.:40            
##  Max.   :100    Max.   :10        Max.   :80.00   Max.   :60            
##  NA's   :7      NA's   :11        NA's   :6       NA's   :9             
##  Solidago_rigida Sphaeralcea_coccinea  Stipa_comata    Stipa_spartea  
##  Min.   :10      Min.   :20           Min.   : 10.00   Min.   : 20.0  
##  1st Qu.:10      1st Qu.:20           1st Qu.: 42.50   1st Qu.: 42.5  
##  Median :10      Median :30           Median : 85.00   Median : 65.0  
##  Mean   :10      Mean   :32           Mean   : 68.33   Mean   : 62.5  
##  3rd Qu.:10      3rd Qu.:40           3rd Qu.: 97.50   3rd Qu.: 85.0  
##  Max.   :10      Max.   :50           Max.   :100.00   Max.   :100.0  
##  NA's   :11      NA's   :7            NA's   :6        NA's   :8      
##  Stipa_viridula Symphoricarpos_occidentalis Taraxacum_officinale
##  Min.   :10.0   Min.   :10.0                Min.   :10          
##  1st Qu.:10.0   1st Qu.:17.5                1st Qu.:15          
##  Median :15.0   Median :20.0                Median :20          
##  Mean   :27.5   Mean   :17.5                Mean   :20          
##  3rd Qu.:32.5   3rd Qu.:20.0                3rd Qu.:25          
##  Max.   :70.0   Max.   :20.0                Max.   :30          
##  NA's   :8      NA's   :8                   NA's   :9           
##  Thermopsis_rhombifolia Tragopogon_dubius Vicia_americana  Viola_adunca 
##  Min.   :10             Min.   :10        Min.   :20      Min.   :10.0  
##  1st Qu.:10             1st Qu.:10        1st Qu.:20      1st Qu.:12.5  
##  Median :30             Median :10        Median :20      Median :15.0  
##  Mean   :30             Mean   :10        Mean   :30      Mean   :15.0  
##  3rd Qu.:45             3rd Qu.:10        3rd Qu.:35      3rd Qu.:17.5  
##  Max.   :60             Max.   :10        Max.   :50      Max.   :20.0  
##  NA's   :5              NA's   :10        NA's   :9       NA's   :10    
##  Zigadenus_venenosus
##  Min.   :50         
##  1st Qu.:50         
##  Median :50         
##  Mean   :50         
##  3rd Qu.:50         
##  Max.   :50         
##  NA's   :11
library (vegan)
## Loading required package: permute
## Loading required package: lattice
## This is vegan 2.4-3
plant_abundance [is.na (plant_abundance)]<-0
rownames (plant_abundance) <-plant_abundance$Habitat #Replace row names with Habitat
plant_abundance$Habitat <-NULL
spplant_abundance<-specnumber(plant_abundance)
Hplant_abundance<-diversity(plant_abundance, index ="shannon")
Dplant_abundance <-diversity(plant_abundance, index = "invsimpson")
diversityResult <-data.frame(spplant_abundance, Hplant_abundance, Dplant_abundance)
diversityResult$Habitat <-rownames(diversityResult)
diversityResult$Habitat <- as.factor(c ("A","A","A","A", "B","B","B","B", "C", "C", "C","C"))

Important Note: Once you get the final dataframe for your diversity indices above, you must as a column to create an (A, B, C) factor to run an ANOVA. To do this…

yourPlantDataframeName$HabitatFactor <- c(A,A,A,A,B,B,B,B,C,C,C,C)

ANSWER HERE

Q3: Choose one of the diversity indices for the plant abundance dataset. Run an ANOVA to analyze the results (check your assumptions). Supply the following:

A) Plot of your data

#ANOVA
PlantD.aov <- aov(Dplant_abundance ~ Habitat, data = diversityResult)
summary(PlantD.aov)
##             Df Sum Sq Mean Sq F value Pr(>F)
## Habitat      2  61.13   30.56   1.498  0.274
## Residuals    9 183.62   20.40
plot(PlantD.aov)

plot(Dplant_abundance ~ Habitat, data = diversityResult)

B) evidence of residual normality and homoscedasticity

ANSWER HERE

hist (diversityResult$Dplant_abundance) #data is normal 

qqnorm (diversityResult$Dplant_abundance)
qqline (diversityResult$Dplant_abundance)

C) ANOVA output

ANSWER HERE

#ANOVA
PlantD.aov <- aov(Dplant_abundance ~ Habitat, data = diversityResult)
summary(PlantD.aov)
##             Df Sum Sq Mean Sq F value Pr(>F)
## Habitat      2  61.13   30.56   1.498  0.274
## Residuals    9 183.62   20.40
plot(PlantD.aov)

D) Tukey HSD results (if applicable)

#I did not run the Tukey HSD test becuase the ANOVA is not signigicant, greater than 0.05.

E) Reported Results Paragraph

#The dataset measuring plant abundance for twelve grassland plots in Kansas is not significant. ANOVA P-value = 0.274. Data was not necessary to be transformed because it was normal and homoscedasticity, neither was necessary to run the Tukey HSD

F) graph created with the plotting gizmo. Be sure to include an informative figure captions for the graphs.

GIZMO GIVEN BELOW. Remember: You need to adjust the parameters.

library(plyr)
library(ggplot2)

xData <- diversityResult$Habitat
xLabel <- "X Habitat"
yData <- diversityResult$Dplant_abundance
yLabel <- "Y diversityResult$Dplant_abundance"
myTitle <- "Plant_abundance"
fontSize <- 18 # Adjust font size
# ^^^^^ adjust these parameters ^^^^^^

# vvvvv leave everything below alone! vvvvvv
temp.df <- data.frame(xData, yData) 
temp.df <- na.omit(temp.df) 
meansErrBars.df <- ddply(temp.df, c("xData"), summarise, N=sum(yData), mean=mean(yData), sd=sd(yData), se=sd/sqrt(N))
graphIT <- ggplot(data = meansErrBars.df, aes(x = xData, y = mean))
limits <- aes(ymax = meansErrBars.df$mean + meansErrBars.df$se, ymin = meansErrBars.df$mean - meansErrBars.df$se)
dodge <- position_dodge(width = 1)
graph_output <- graphIT + 
labs(x = xLabel, y = yLabel, title = myTitle) +
geom_bar(stat = "identity", position = dodge, fill="gray", color = "black") + 
geom_errorbar(limits, width = 0.6, stat ="identity", position = dodge, size = 1) +
geom_point(data = temp.df, aes(x = xData, y = yData), position = dodge, size = 8, shape=1) +
theme_classic() + theme(axis.text=element_text(size=fontSize*3.5/4), 
axis.title.y=element_text(size=fontSize,face="bold", vjust=1.5),
axis.title.x=element_text(size=fontSize,face="bold", vjust=-0.3),
plot.title = element_text(size=fontSize,face="bold", vjust=1.5),
panel.border = element_rect(colour = "black", fill=NA, size=3))
print(graph_output)

remove(temp.df, meansErrBars.df, graphIT, limits, dodge, fontSize, myTitle, xData, xLabel, yData, yLabel) #clean up

Please turn–in your homework via Sakai by saving and submitting an R Markdown PDF or HTML file from R Pubs!