Last active
July 5, 2017 08:52
-
-
Save geofis/a632b1f5faaee245fd3659c126efbc7e to your computer and use it in GitHub Desktop.
Asignatura Biogeografía, GEO131, UASD, semestre 2016-02. Prácticas 10. Matriz abundancia, matriz comunidad, matriz ambiental, indices diversidad, mapa en R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ###INICIO VIDEO: https://www.youtube.com/watch?v=OHdJ3m3QUuQ | |
| ###LISTA DE REPRODUCCION: https://www.youtube.com/watch?v=8uHnf_1W7D8&list=PLDcT2n8UzsCTkT7Ylgjll5Zxyrj30_lc1 | |
| #MATRIZ DE ABUNDANCIA, MATRIZ DE COMUNIDAD, MATRIZ AMBIENTAL, INDICES DE DIVERSIDAD, MAPA | |
| library(vegan) | |
| library(BiodiversityR) | |
| library(reshape2) | |
| library(stringr) | |
| library(sp) | |
| library(plotGoogleMaps) | |
| library(plotKML) | |
| #MATRIZ DE ABUNDANCIA | |
| d <- read.csv("http://www.geografiafisica.org/sem_2016_02/geo131/datos/he/he_ma.csv") | |
| str(d) | |
| head(d) | |
| #RESUMEN DE RIQUEZA GENERAL, RIQUEZA POR GENEROS, ABUNDANCIA POR ESPECIE, ABUNDANCIA POR GENEROS | |
| gendcesp <- word(unique(d$ESPECIE),1, sep=' ' ) | |
| gendcesp | |
| genriq <- sort(table(gendcesp), decreasing = T) | |
| genriq | |
| gendcind <- word(d$ESPECIE,1, sep=' ' ) | |
| gendcind | |
| genabun <- sort(table(gendcind), decreasing = T) | |
| genabun | |
| #MATRIZ DE COMUNIDAD A PARTIR DE LA DE ABUNDANCIA | |
| d.mc <- dcast(d, ID~ESPECIE, fun.aggregate=length, value.var = 'ESPECIE') | |
| d.mc | |
| rownames(d.mc) <- d.mc[,1] | |
| d.mc <- d.mc[,-1] | |
| str(d.mc) | |
| #MATRIZ AMBIENTAL | |
| d.env <- read.csv("http://www.geografiafisica.org/sem_2016_02/geo131/datos/he/he_env.csv") | |
| d.env | |
| str(d.env) | |
| #VERIFICACION DE INTEGRIDAD DE LOS DATOS | |
| table(d$ID) #FRECUENCIAS DE PARCELAS DESDE LA MATRIZ DE ABUNDANCIA. EL RESULTADO CORRESPONDE A LA ABUNDANCIA POR TRANSECTO, DADO QUE CADA FILA ES UN INDIVIDUO | |
| rownames(d.mc) | |
| table(d.env$ID) #CONTEO DE FRECUENCIAS DE PARCELAS DESDE LA MATRIZ AMBIENTAL. EL RESULTADO DEBERIA SER 1 EN CADA CASO, DADO QUE CADA FILA ES UN TRANSECTO | |
| length(table(d$ID)) #NUMERO DE PARCELAS UNICAS EN LA MATRIZ DE ABUNDANCIA. EL TOTAL DEBERIA SER EQUIVALENTE AL NUMERO DE TRANSECTOS | |
| length(table(d.env$ID)) #NUMERO DE PARCELAS UNICAS EN LA MATRIZ AMBIENTAL. EL TOTAL DEBERIA SER EQUIVALENTE AL NUMERO DE TRANSECTOS | |
| nrow(d.mc) | |
| merge(as.data.frame(table(d.env$ID)),as.data.frame(table(d$ID)),by = 'Var1', all = T) #ESTA UNION DEBE MOSTRAR UN NUMERO SIMILAR DE ENTRADAS ENTRE FUENTES. NO DEBEN APARECER "NA" EN NINGUN CASO. LA COLUMNA "Freq.x" INDICA EL NUMERO DE VECES QUE APARECE EL NOMBRE DE UN TRANSECTO EN LA MATRIZ AMBIENTAL. LA COLUMNA "Freq.y" INDICA EL NUMERO DE VECES QUE APARECE EL NOMBRE DE UN TRANSECTO EN LA MATRIZ DE ABUNDANCIA | |
| merge(as.data.frame(table(d.env$ID)),as.data.frame(table(rownames(d.mc))),by = 'Var1', all = T) #IDEM, PERO PONE EN RELACION LAS MATRICES AMBIENTAL Y DE COMUNIDAD | |
| d.env$ID==rownames(d.mc) | |
| #DESDE MATRIZ AMBIENTAL. RIQUEZA Y ABUNDANCIA. SIN ADJUNTAR RESULTADOS A MATRIZ AMBIENTAL | |
| specnumber(d.mc) #RIQUEZA POR TRANSECTO | |
| sort(specnumber(d.mc), decreasing = T) | |
| specnumber(colSums(d.mc)) #RIQUEZA TOTAL | |
| sort(colSums(d.mc), decreasing = T) #ABUNDANCIA POR ESPECIE | |
| rowSums(d.mc) #ABUNDANCIA POR TRANSECTO | |
| sort(rowSums(d.mc), decreasing = T) | |
| #INDICES. ADJUNTAR A MATRIZ AMBIENTAL | |
| diversity(d.mc) | |
| diversityresult(d.mc,index='Shannon',method='s') | |
| diversityresult(d.mc,index='Shannon',method='s', digits = 4) | |
| diversityresult(d.mc,index='Shannon',method='s', digits = 4, sortit = T) | |
| diversityresult(d.mc,index='Shannon',method='all', digits = 4) | |
| indices <- cbind(ID=rownames(d.mc),as.data.frame(sapply(c("richness","abundance","Shannon","Simpson","inverseSimpson","Logalpha","Berger","Jevenness","Eevenness" ),function(x) diversityresult(d.mc,index=x,method='s', digits = 4)))) | |
| indices | |
| colnames(indices)[2:ncol(indices)] <- c('riqueza','abundancia','Shannon','Gini-Simpson','inverso de Simpson','Fisher-alpha o Logalpha','Berger-Parker','equidad de Pielou o J-evenness','equidad de Buzas-Gibson o E-evenness') | |
| indices | |
| #UNIENDO A MATRIZ AMBIENTAL | |
| d.env <- merge(d.env, indices) | |
| d.env | |
| #MAPA | |
| d.env.sp <- d.env[,c('ID','x','y')] | |
| d.env.sp | |
| coordinates(d.env.sp) <- ~x+y #CONVIERTE A UN OBJETO ESPACIAL | |
| d.env.sp | |
| proj4string(d.env.sp) <- CRS("+init=epsg:32619") #ASIGNA EL SISTEMA DE REFERENCIA DE COORDENADAS EPSG:32619 | |
| d.env.sp | |
| dev.new(); spplot(d.env.sp,"ID") #DESPLIEGA UN MAPA MUDO SEGUN LA PALETA DE COLORES POR DEFECTO | |
| plotGoogleMaps(d.env.sp,iconMarker='',zcol="ID","d.env.sp.html") #ARCHIVO html EN EL DIRECTORIO DE TRABAJO. EL ARCHIVO html CREADO SE ABRIR? AUTOM?TICAMENTE EN UNA VENTANA DEL NAVEGADOR PREDETERMINADO | |
| plotKML(d.env.sp) #KML EN DIRECTORIO DE TRABAJO | |
| ###FIN VIDEO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment