A colleague of yours is working on a project on banner-tailed kangaroo rats (Dipodomys spectabilis) and is interested in what elevations these mice tend to occupy in the continental United States. You offer to help them out by getting some coordinates for specimens of this species and looking up the elevation of these coordinates.
Start by getting banner-tailed kangaroo rat occurrences from GBIF, the Global
Biodiversity Information Facility, using the spocc
R
package, which is designed to retrieve species occurrence data from various
openly available data resources. Use the following code to do so:
```
dipo_df = occ(query = "Dipodomys spectabilis",
from = "gbif",
limit = 1000,
has_coords = TRUE)
dipo_df = data.frame(dipo_df$gbif$data)
```
Dipodomys_spectabilis.basisOfRecord
that is PRESERVED_SPECIMEN
and a Dipodomys_spectabilis.countryCode
that is US
0
for Dipodomys_spectabilis.latitude
or
Dipodomys_spectabilis.longitude
Dipodomys_spectabilis.latitude
and Dipodomys_spectabilis.longitude
and
rename these columns to latitude
and longitude
using select
. You can
rename while selecting columns using a format like this one
select(new_column_name = old_column_name)
head()
function to show the top few rows of this cleaned datasetusmap = map_data("usa")
geom_polygon
. In the aesthetic use group = group
to avoid weird lines cross your graph. Use fill = "white"
and color = "black"
.coord_quickmap()
to automatically use a reasonable spatial projection