Skip to content

Instantly share code, notes, and snippets.

@emhart
Created July 3, 2014 22:36
Show Gist options
  • Save emhart/267173fae77277b3dd37 to your computer and use it in GitHub Desktop.
Save emhart/267173fae77277b3dd37 to your computer and use it in GitHub Desktop.
For Bennet, overlaying species
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