setwd("~/Dropbox/R pages") # modificando o texto colorido e mantendo as aspas você especifica o diretório odw salvou a base
df.aves<-read.csv("d_aves.csv", sep=";")
df.aves
## especie ccs SAF
## 1 canario_terra 1 4
## 2 anu_preto 3 0
## 3 Tyrannus_sp1 2 0
## 4 Gaviao_asa_branca 3 0
## 5 beija_flor peq 1 0
## 6 Fluvicola_nengeta 3 3
## 7 Gaviao_preto 2 0
## 8 Tyrannus_sulfuratus 1 4
## 9 marrom_asa_escura 0 2
## 10 preto_peq 0 9
## 11 periquito_verde 0 2
## 12 cinza_barr_clara 0 3
## 13 rouxinol 0 1
## 14 jandaia 0 1
## 15 periquito_verde_ama 0 1
## 16 cinza_azul 0 4
## 17 sabiá 0 2
## 18 Urubu 0 1
require(ggplot2)
## Loading required package: ggplot2
ggplot(df.aves, aes(especie, ccs))+geom_col() # ficou mal, fora de ordem. Vamos consertar
if (!require("tidyverse")) install.packages('tidyverse')
require(tidyverse)
df.aves.ccs<-df.aves[-3]%>%filter(ccs>0) # retirei as aves do SF e todas que eram abundancia zero no CCS, ou seja exclusivas do SAF
df.aves.ccs
## especie ccs
## 1 canario_terra 1
## 2 anu_preto 3
## 3 Tyrannus_sp1 2
## 4 Gaviao_asa_branca 3
## 5 beija_flor peq 1
## 6 Fluvicola_nengeta 3
## 7 Gaviao_preto 2
## 8 Tyrannus_sulfuratus 1
ggplot(df.aves.ccs, aes(x=reorder(especie, -ccs),y=ccs))+
geom_col()+ # agora tá na ordem
theme(axis.text.x=element_text(angle=45, hjust=1))+
labs(x="espécies de aves", y = "abundâncias")
df.aves.saf<-df.aves[-2]%>%filter(SAF>0) # retirei as aves do CCS e todas que eram abundancia zero no SAF, ou seja exclusivas do SAF
df.aves.saf
## especie SAF
## 1 canario_terra 4
## 2 Fluvicola_nengeta 3
## 3 Tyrannus_sulfuratus 4
## 4 marrom_asa_escura 2
## 5 preto_peq 9
## 6 periquito_verde 2
## 7 cinza_barr_clara 3
## 8 rouxinol 1
## 9 jandaia 1
## 10 periquito_verde_ama 1
## 11 cinza_azul 4
## 12 sabiá 2
## 13 Urubu 1
ggplot(df.aves.saf, aes(x=reorder(especie, -SAF),y=SAF))+
geom_col()+ # agora tá na ordem
theme(axis.text.x=element_text(angle=45, hjust=1))+
labs(x="espécies de aves", y = "abundâncias")
library(vegan) # chamei o Vegan
index.div.ccs<-list(diversity(df.aves[,2], index = "shannon"), diversity(df.aves[,2], index = "simpson")) # gerei uma lista com valores de diversidade de shannon e simpson.
index.div.ccs
## [[1]]
## [1] 1.981333
##
## [[2]]
## [1] 0.8515625
index.div.SAF<-list(diversity(df.aves[,3], index = "shannon"), diversity(df.aves[,3], index = "simpson")) # gerei uma lista com valores de diversidade de shannon e simpson.
index.div.SAF
## [[1]]
## [1] 2.336293
##
## [[2]]
## [1] 0.880935
simi.bray.aves<-vegdist(t(df.aves[,-1]), method = "bray") # gerei uma matriz de dissimilaridade usando o método de Bray-Curtis que considera as abundâncias> ote que tirei a coluna com os nomes das aves, pois ele não entende
simi.bray.aves # esse é o velor de semilaridade segndo o índices d Bray Curtis
## ccs
## SAF 0.8113208
Vamos agora entender como a beta-diversidade pode ser calculada com base nos números de Hill e portanto gerar beta diversidade verdadeira. Para isso, vamos recordar a relação proposta por Whittaker sobre as magnitudes da diversidade:
\(\gamma=\alpha*\beta\)
if (!require("entropart")) install.packages('entropart')
library(entropart)
MC<-MetaCommunity(df.aves[,-1])
summary(MC)
## Meta-community (class 'MetaCommunity') made of 53 individuals in 2
## communities and 18 species.
##
## Its sample coverage is 0.909163522948495
##
## Community weights are:
## ccs SAF
## 0.5 0.5
## Community sample numbers of individuals are:
## ccs SAF
## 16 37
## Community sample coverages are:
## ccs SAF
## 0.8238095 0.8961844
# Agora vamos calculara a diversidade alfa verdadeira nos três níveis
AlphaDiversity(MC, 0, Correction = "None") # veja o output, o progrma dá um alfa para cada fragmentos da usina e uma alfa média = $Total
## $MetaCommunity
## [1] "MC"
##
## $Method
## [1] "Neutral"
##
## $Type
## [1] "alpha"
##
## $Order
## [1] 0
##
## $Correction
## [1] "None"
##
## $Normalized
## [1] TRUE
##
## $Weights
## ccs SAF
## 0.5 0.5
##
## $Communities
## ccs SAF
## 8 13
##
## $Total
## [1] 10.5
##
## attr(,"class")
## [1] "MCdiversity"
AlphaDiversity(MC, 1, Correction = "None") # para ordem q= 1
## $MetaCommunity
## [1] "MC"
##
## $Method
## [1] "Neutral"
##
## $Type
## [1] "alpha"
##
## $Order
## [1] 1
##
## $Correction
## [1] "None"
##
## $Normalized
## [1] TRUE
##
## $Weights
## ccs SAF
## 0.5 0.5
##
## $Communities
## ccs SAF
## 7.25240 10.34283
##
## $Total
## [1] 8.66085
##
## attr(,"class")
## [1] "MCdiversity"
AlphaDiversity(MC, 2, Correction = "None") # para ordem q = 2
## $MetaCommunity
## [1] "MC"
##
## $Method
## [1] "Neutral"
##
## $Type
## [1] "alpha"
##
## $Order
## [1] 2
##
## $Correction
## [1] "None"
##
## $Normalized
## [1] TRUE
##
## $Weights
## ccs SAF
## 0.5 0.5
##
## $Communities
## ccs SAF
## 6.736842 8.398773
##
## $Total
## [1] 7.476565
##
## attr(,"class")
## [1] "MCdiversity"
# Agora vamos calcular Beta
summary(BetaDiversity(MC, 0, Correction = "None")) # aqui peço as betas já na forma de summary
## Neutral beta diversity of order 0 of metaCommunity MC with correction:
## None
##
## Average diversity of the communities:
## [1] 1.714286
summary(BetaDiversity(MC, 1, Correction = "None"))
## Neutral beta diversity of order 1 of metaCommunity MC with correction:
## None
##
## Average diversity of the communities:
## [1] 1.646768
summary(BetaDiversity(MC, 2, Correction = "None"))
## Neutral beta diversity of order 2 of metaCommunity MC with correction:
## None
##
## Average diversity of the communities:
## [1] 1.646499
# Por último as Gamas
GammaDiversity(MC, 0, Correction = "None") # A gama de ordem zero é igual à riqeuza, portanto, 15
## None
## 18
GammaDiversity(MC, 1, Correction = "None") # Igual ao exponencial de Shannon
## None
## 14.26241
GammaDiversity(MC, 2, Correction = "None") # Igual ao invero de simpson
## None
## 12.31016
###Finalmente para entendermos a reação entre Alfa, Beta e Gama. Só é preciso mudar entre 0, 1 e 2 para obter para todas as ordens q de
summary(DivPart(q = 0, MC, Biased = FALSE, Correction = "None") -> dp0)
## HCDT diversity partitioning of order 0 of metaCommunity MC
## with correction: None
## Alpha diversity of communities:
## ccs SAF
## 8 13
## Total alpha diversity of the communities:
## [1] 10.5
## Beta diversity of the communities:
## None
## 1.714286
## Gamma diversity of the metacommunity:
## None
## 18
plot(dp0)
summary(DivPart(q =1, MC, Biased = FALSE, Correction = "None") -> dp1)
## HCDT diversity partitioning of order 1 of metaCommunity MC
## with correction: None
## Alpha diversity of communities:
## ccs SAF
## 7.25240 10.34283
## Total alpha diversity of the communities:
## [1] 8.66085
## Beta diversity of the communities:
## None
## 1.646768
## Gamma diversity of the metacommunity:
## None
## 14.26241
plot(dp1)
summary(DivPart(q = 2, MC, Biased = FALSE, Correction = "None") -> dp2)
## HCDT diversity partitioning of order 2 of metaCommunity MC
## with correction: None
## Alpha diversity of communities:
## ccs SAF
## 6.736842 8.398773
## Total alpha diversity of the communities:
## [1] 7.476565
## Beta diversity of the communities:
## None
## 1.646499
## Gamma diversity of the metacommunity:
## None
## 12.31016
plot(dp2)