Script to grab land use data

https://pakillo.github.io/R-GIS-tutorial/#vector

load libraries

*tidyr and magrittr mess up extract function

library(foreign)
#library(dplyr)
#library(magrittr)
#library(tidyr)
library(gridExtra)
library(ggplot2)
#spatial
library(raster)
## Loading required package: sp
library(rasterVis)
## Warning: package 'rasterVis' was built under R version 3.3.2
## Loading required package: lattice
## Loading required package: latticeExtra
## Loading required package: RColorBrewer
## 
## Attaching package: 'latticeExtra'
## The following object is masked from 'package:ggplot2':
## 
##     layer
library(rgdal)
## rgdal: version: 1.1-10, (SVN revision 622)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 1.11.4, released 2016/01/25
##  Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgdal/gdal
##  Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
##  Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgdal/proj
##  Linking to sp version: 1.2-3
library(dismo)

Test case for 1 species

#load image of land use into R
x<-raster("GLOBCOVER_L4_200901_200912_V2.3.tif")

#plot it to see if we did it right
plot(x,axes=T,xlim=c(-150,-30),ylim=c(-50,50))

##reading in Triatoma nitida
#Tnit<-read.csv("Globcover2009_V2.3_Global_/Triatoma_nitida.csv",header=TRUE)
#points(Tnit$Lon,Tnit$Lat,cex=1,pch=16,col="red") run this code with previous line to put points onto the map

#no clue waht this does, but following the code
#coordinates(Tnit)<-Tnit[,c("Lon","Lat")]
#it looks like it converted lon lat into spaace
#plot(Tnit)

#important code: projecting points from lat lon into space
crs.go<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")
#proj4string(Tnit)<-crs.go
#summary(Tnit)

#extract values of lat lon from the raster file
#Tnit$worked<-extract(x,cbind(Tnit$Lon,Tnit$Lat))
#Tnit$worked

For whole dataset presence

whole<-read.csv("20160328_species_distribution.csv",skip=0)#"metadata on first 2 lines"
coordinates(whole)<-whole[,c("Lon","Lat")]
plot(whole)