CornellLabofOrnithology / ebird-best-practices

Best Practices for Using eBird Data
https://CornellLabOfOrnithology.github.io/ebird-best-practices/
Other
32 stars 12 forks source link

Selecting a portion of the map for encounter rates #10

Closed lime-n closed 4 years ago

lime-n commented 4 years ago

I have implemented code that plots species encounter rate of the Northern Bobwhite onto a map, whilst only displaying data for a small portion of this map. However, the plotted map shows the entire region, in this case North America, I wish for only the area displayed with data to show.

I have been following the code as it is.

This is what it looks like: enter image description here

What I want it to look like: enter image description here

mstrimas commented 4 years ago

Again, this is more of a general spatial R questions, but the idea is you either need to:

lime-n commented 4 years ago

I found that the mistake was at the beginning of the book, which is easily corrected and may have been a simple miss when writing the code.

when reading the bcr code at the beginning:

> bcr <- read_sf("data/gis-data.gpkg", "bcr") %>% 
st_transform(crs = map_proj) %>% 
 st_geometry()

It is best to include:

filter(bcr_code == 27) %>% 

to make sure you filter only the bcr region.

This gives the desired second image above.

mstrimas commented 4 years ago

What "data/gis-data.gpkg" file are you using? The one available for download via the website only includes BCR 27 so you shouldn't need to use filter(bcr_code == 27)

lime-n commented 4 years ago

That makes plenty of sense now! I was using the older gis geopackage that included all of the bcr regions.