0

I have a dataset which looks like this(subset):

Latitude        Longitude   Species
-34,68871595    20,0331831  Ischnura senegalensis   
-34,59082383    20,05421162 Ceriagrion glabrum  
-34,59082383    20,05421162 Crocothemis erythraea   
-34,59082383    20,05421162 Ischnura senegalensis   
-34,63333333    20,05       Africallagma glaucum        
-34,53333333    20,05       Africallagma glaucum    
-34,53333333    20,05       Ceratogomphus pictus            
-34,53333333    20,05       Crocothemis sanguinolenta           
-34,30          18,45       Orthetrum julia
-34,35          18,45       Orthetrum julia            

First I plot the data on a map of Southern Africa. What I want to obtain as output is a dataframe where for each cell of my grid I obtain the number of individuals within the cell, as well as number of species. The cell size I am wanting is a half degree cell which is align with the centre of the latitude and longitude of my map i.e one cell centre will be on -34(lat) and 20(long)

My code insofar-
###plotting data points
lonlat<-cbind(Longitude,Latitude)
library(sp)
pts<-SpatialPoints(lonlat)
showDefault(pts)
crdref<-CRS('+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0')
pts<-SpatialPoints(lonlat,proj4string = crdref)
Sppnames<-SA.ODA$Species
df<-data.frame(lonlat,Sppnames)
ptsdf<-SpatialPointsDataFrame(pts,data = df)

###Plotting a Africa base map
mapofSA<-readRDS('/Users/Ashleigh/Desktop/gadm36_ZAF_0_sp.rds')
proj4string(mapofSA)<-CRS('+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0')
  • How far have you got? Have you read the data in? Into a data frame, or a spatial data frame? Have you looked at any tutorials for spatial data in R? – Spacedman Feb 26 at 8:49
  • I have managed to extract data as stated in the question gis.stackexchange.com/questions/210092/…. To be more precise with my previous question I would like to create a presence absence data set, as well as a data frame with the summary of each cell (number of species and number of individuals) many thanks – A Basel Feb 27 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.