2

I am attempting to subset and project an ecoregions shapefile from : EPA ECOREGIONS my data set is found here: SHAPEFILES and RASTER When I run this code, two major problems occur: 1) I cannot get the subset of ecoregions to plot on top of my raster file and 2) I cannot extract the values (summary information) from the subset of ecoregions from the raster. Can anyone help with this?

require (raster) raster<-raster('FG_RCP26_2050.tif') 
plot (raster)

Raster with Data

ecoregions.all<- readOGR("NA_CEC_Eco_Level2.shp",layer="NA_CEC_Eco_Level2") 
head (ecoregions.all) 
plot (ecoregions.all)

ecoregions

#this is the subset of ecoregions that I need 
NA_L2<-c('5.1','5.2','5.3','8.1','8.3','8.4','8.5')

#subset the ecoregion.all to just those in the northeast
#this must be where the problem is 
ne.ecoregions = coregions.all[match(toupper(NA_L2),toupper(ecoregions.all$NA_L2CODE)),]

#plot ne.ecoregions on top of raster and extract summary statistics for each ecoregion 
#summary statistics =distribution of values within each ecoregion
plot (raster) plot (ne.ecoregions, add=T)

ecoregions.raster<-mask (raster, ne.ecoregions) 
summary (ecoregions.raster)
  • Could you please focus this a bit by defining a question? You might also want to add an R tag to get more attention. – Aaron May 27 '14 at 13:15
  • and instead of using mask, try using the extract command. Works miracles ;) – Curlew May 27 '14 at 13:35
  • Hm, there's a file named 'siteXspecies.csv', but no raster in your Dropbox folder. – fdetsch May 18 '15 at 9:03

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.