Created
July 3, 2014 22:36
-
-
Save emhart/267173fae77277b3dd37 to your computer and use it in GitHub Desktop.
For Bennet, overlaying species
This file contains 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
library("sp") | |
library("maptools") | |
options(stringsAsFactors=F) | |
coords <- read.csv("~/Downloads/latlongcoord.csv") | |
biome<-readShapeSpatial("~/Downloads/official/wwf_terr_ecos.shp") | |
### Load subset of data just as a quick test | |
spobj <- SpatialPoints(as.matrix(coords[1:100,c('decimalLongitude','decimalLatitude')])) | |
sp_df <- SpatialPointsDataFrame(spobj,data = data.frame(coords[1:100,c('Species')])) | |
### Change name | |
names(sp_df) <- "species" | |
tdat <- vector() | |
for (i in unique(sp_df$species)) { | |
tmp_sp <- sp_df[which(sp_df$species == i), ] | |
tmp_t <- as.character(over(tmp_sp, biome)$ECO_NAME) | |
tdat <- c(tdat, tmp_t) | |
} | |
###Seee associations betwees species and ecoregion | |
table(tdat,sp_df$species) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment