In [ ]:
install.packages("vegan") #Installing the 'vegan' package to run the diversity analysis
library(vegan) #calling the 'vegan' package into this notebook
library(dplyr) #calling the 'dplyr' package to do data cleaning functions
In [11]:
dat <- read.csv("karakoram.csv") #reading in and examining the CSV file
head(dat) #Taking a look at the data
str(dat) #This function allows you to look at structure of the object, and here you see some of the values are 'int' not numeric ('num')
A data.frame: 4 × 133
X0Aconitum.heterophyllumAconitum.myosotisAconogonon.alpinumAdiantum.sp.Alchemella.ypsilotomaAllardia.stoliczkaeAllium.carolinianumAnaphalis.nepalensisAndrosace.baltistanica⋯Swertia.cordataSwertia.sp.Tanacetum.falconeriTanacetum.gracileTaraxacum.offionalisThalictrum.sp.Thlaspi.andersoniiThlaspi.cochlearioidesViola.rupestrisWhite.Queen.anne.s.Lace
<chr><dbl><dbl><dbl><int><int><dbl><int><dbl><int>⋯<int><dbl><dbl><dbl><int><int><int><int><int><int>
1Baumharel 1.50.030.5000.0 013.00⋯01.5 0.00.0 100001
2Deosai Top 1.00.0 9.0000.028 0.00⋯11.012.00.0 300003
3Mir Khun 0.02.5 0.0001.5 1 1.51⋯00.0 1.00.01001100
4Thalle Happen0.00.0 1.0100.0 115.00⋯00.0 0.50.5 840010
'data.frame':	4 obs. of  133 variables:
 $ X0                          : chr  "Baumharel" "Deosai Top" "Mir Khun" "Thalle Happen"
 $ Aconitum.heterophyllum      : num  1.5 1 0 0
 $ Aconitum.myosotis           : num  0 0 2.5 0
 $ Aconogonon.alpinum          : num  30.5 9 0 1
 $ Adiantum.sp.                : int  0 0 0 1
 $ Alchemella.ypsilotoma       : int  0 0 0 0
 $ Allardia.stoliczkae         : num  0 0 1.5 0
 $ Allium.carolinianum         : int  0 28 1 1
 $ Anaphalis.nepalensis        : num  13 0 1.5 15
 $ Androsace.baltistanica      : int  0 0 1 0
 $ Androsace.himalaica         : int  0 17 0 0
 $ Androsace.sp.               : int  0 0 3 2
 $ Apiaceae.sp.                : int  0 0 1 0
 $ Aquilegia.fragrans          : num  1.5 0 0 0
 $ Arabidopsis.mollissima      : int  0 0 0 1
 $ Artemisia.japonica          : int  0 4 0 0
 $ Aster.falconeri             : num  2 3.5 6 3
 $ Bergenia.stracheyi          : num  0 0.5 0.5 0.5
 $ Bistorta.vivipara           : num  3.5 22.5 29 18
 $ Brachyactis.sp.             : num  0 0 1.5 0
 $ Bramia.monnieri             : num  0 0 0 0.5
 $ Bupleurum.longicaule        : num  3 0.5 0 0
 $ Bupleurum.sp                : num  0 0 3.5 0.5
 $ Carex.cruenta               : num  0 0 0.5 0
 $ Carex.melanantha            : num  0 0 0 0.5
 $ Carex.nivalis               : num  10.5 35 140.5 90
 $ Carex.sp                    : num  5.5 0 0 0
 $ Cerastium.cerastioides      : num  1.5 0 39 2
 $ Cicer.sp                    : int  3 0 0 0
 $ Codonopsis.clematidea       : int  1 0 0 0
 $ Comastoma.boreale           : int  0 0 11 3
 $ Cortia.sp                   : num  0 0 1.5 0
 $ Corydalis.gortschakovii     : num  0 1 1.5 0
 $ Cremanthodium.decaisnei     : num  0 0 1.5 0
 $ Deliphinium.brunonianum     : num  0 0 1 0.5
 $ Draba.altaica               : int  0 0 4 0
 $ Draba.oreades.Schrenk       : int  0 15 0 0
 $ Draba.setosa                : int  0 0 1 0
 $ Elymus.sp                   : num  0 0 1 0.5
 $ Epilobium.latifolium        : num  1.5 0 0 1
 $ Epilobium.sp                : int  1 0 0 0
 $ Erigeron.acer               : num  0 0 0 0.5
 $ Erigeron.alpinum.L.         : int  0 0 2 1
 $ Erigeron.roylei             : num  0 0 2.5 1
 $ Erigeron.sp                 : num  0.5 0.5 0 0
 $ Euphrasia.aristulata        : num  1.5 0 0 0
 $ Euphrasia.sp.               : int  0 0 0 1
 $ Fern.sp                     : num  1.5 0 0 0
 $ Gentiana.argentia           : num  1 0.5 29 2
 $ Gentianodes.eumarginata     : num  0 0 0.5 0.5
 $ Gentianoides.tianschanica   : num  0 0.5 0 0
 $ Geranium.pratense           : num  25.5 0.5 4 6
 $ Hieracium.sp.               : int  0 0 4 3
 $ Jaeschkea.oligosperma       : int  0 0 0 1
 $ Juncus.articulatus          : num  0 0 0 0.5
 $ Lactuca.lessertiana         : num  0.5 0.5 0 1
 $ Lactuca.sp.                 : int  1 0 0 0
 $ Leontopodium.jacotianum     : num  0 0 1.5 7
 $ Leontopodium.leontopodinum  : num  2 10.5 25.5 2
 $ Lindelofia.anchusoides      : int  0 0 2 1
 $ Lindelofia.stylosa          : num  0 0 0 0.5
 $ Lomatogonium.corinthianum   : int  0 0 0 1
 $ Morina.persica              : num  1.5 0 0 0
 $ Myosotis.alpestris          : num  1 1.5 24.5 13.5
 $ Nepeta.discolor             : num  2 0 3 1.5
 $ Oxyria.digyna               : num  1.5 0.5 1 0
 $ Oxytropis.sp.               : num  1.5 0 32.5 4.5
 $ Papaver.nudicaule           : num  0 0 9.5 1
 $ Pedicularis.bicornuta       : num  0 1.5 0 1
 $ Pedicularis.cheilanthifoliae: num  1.5 3 0 0.5
 $ Pedicularis.pectinata       : int  0 16 1 1
 $ Phleum.alpinum              : num  0 4.5 0 0
 $ Pleurospermum.candolii      : num  0 0 0 0.5
 $ Pleurospermum.hookeri       : num  0 0 17.5 1
 $ Pleurospermum.stellatum     : int  0 0 6 1
 $ Poa.alpina                  : int  1 0 75 23
 $ Poa.sp.                     : num  1 1 1.5 1
 $ Polygonum.amplexicaule      : int  0 0 3 0
 $ Polygonum.sp.               : int  0 0 1 2
 $ Potentilla.anserina         : int  1 1 86 95
 $ Potentilla.dryadanthoides   : int  0 0 0 1
 $ Potentilla.gelida           : int  0 0 8 3
 $ Potentilla.sp.              : num  1.5 0 0 0
 $ Primula.denticulata         : int  0 0 6 4
 $ Primula.macrophylla         : int  0 9 0 0
 $ Psychrogeton.alexeenkoi     : int  2 5 0 0
 $ Pulsatilla.wallichiana      : int  0 1 0 1
 $ Ranunculus.sp.              : num  1.5 1 0 0
 $ Rheum.webbianum             : int  0 0 43 2
 $ Rhodiola.heterodonta        : num  0 0 14.5 2
 $ Rhodiola.wallichiana        : num  1.5 16 0 1
 $ Ribes.sp.                   : num  1.5 0 0 0
 $ Rosularia.alpestris         : int  0 0 0 1
 $ Rumex.acetosa               : int  0 0 1 1
 $ Rumex.nepalensis            : num  0 3.5 0 0
 $ Salix.sp.                   : num  0 0.5 0 0
 $ Saussurea.falconeri         : num  0 0.5 0 0
 $ Saussurea.naphalis          : int  1 0 2 0
 $ Saxifraga.flagellaris       : num  0 12 2.5 1
  [list output truncated]
In [12]:
dat$X0 <- NULL #Removing the first column with the site names because later analysis needs all the values to be numeric
dat<- lapply(dat, as.numeric) #changing all the values to numeric values
In [13]:
dat <- as.data.frame(dat) #setting the data as a tabular dataframe
In [18]:
#Running the diversity function within the 'vegan' package
data(dat) 
shannon <- diversity(dat, index = "shannon") #Using the 'diversity' function, different diversity indices could be calculated (eg. Shannon's, Simpsons)
shannon <- as.data.frame(shannon) #Structuring the results into a tabular dataframe again
shannon
Warning message in data(dat):
“data set ‘dat’ not found”
A data.frame: 4 × 1
shannon
<dbl>
3.113534
3.137401
3.011446
2.729199
In [16]:
#Binding the site names to their associated Shannon's index as they were removed earlier
sitename<-c("Baumharel", "Deosai Top", "Mir Khun", "Thalle Happen")
shannon <- cbind(sitename, shannon)
shannon
A data.frame: 4 × 2
sitenameshannon
<chr><dbl>
Baumharel 3.113534
Deosai Top 3.137401
Mir Khun 3.011446
Thalle Happen2.729199