# install
install.packages("tidyverse") # cleaning data
install.packages("janitor") # cleaning data
install.packages("usethis") # installing eBird API key
install.packages("rebird") # eBird taxonomy data
install.packages("leaflet") # interactive mapWorking with eBird Data
Introduction
This tutorial demonstrates how to access, clean, and visualize bird observation data from eBird using R. We will download our birding data from eBird and work through a reproducible workflow, transforming raw bird observations into an interactive map.
We will begin by importing and cleaning the data, selecting relevant variables, and formatting dates for analysis. Next, we will use the rebird package to access eBird’s taxonomy through its Application Programming Interface (API). Finally, we will use the leaflet package to create an interactive map of our bird sightings, with clickable markers that display observation details and a link to the species’ page on eBird.
The observations used in this vignette come from my personal eBird account and were recorded using the Merlin Bird ID phone app.
R Packages
You will need the following R packages. If you have already installed them, skip the install.packages lines.
# load
library(tidyverse)
library(janitor)
library(usethis)
library(rebird)
library(leaflet)eBird Data
To begin, request your eBird data here. Alternatively, you can open the eBird Homepage and navigate to My eBird and then Download My Data. Either way will bring you to the following page:
Select Request My Observations
You will receive an email from eBird titled “Your eBird data are now available for download.” Click the link provided and your data will automatically download. Find the zipped folder in your Downloads and extract the MyEBirdData.csv file.
Cleaning
We can now bring these data into R using the read.csv function. Be sure to change the file path inside read.csv based on where you have stored your MyEBirdData.csv file.
# load eBird data
my_birds <- read.csv("MyEBirdData.csv")eBird provides a number of variables with these data. We will work Common.Name and Scientific.Name (each bird’s name and scientific name, respectively), as well as the location (Location), coordinates (Latitude/Longitude), and date (Date) of each bird observation.
# clean eBird data
my_birds <- my_birds |>
# OPTIONAL: change variable names to snake_case for cleaner look
clean_names() |>
# fix spelling errors...
mutate(location = (recode(location,
"Yeslar Swamp" = "Yesler Swamp"))) |>
# filter to desired variables
select(name = common_name,
sci_name = scientific_name,
location,
latitude,
longitude,
date)Next, we must format the date variable so that R recognizes it as a date, rather than a character string.
head(my_birds$date)[1] "2026-03-23" "2026-03-23" "2022-11-12" "2026-04-11" "2024-10-12"
[6] "2025-06-18"
typeof(my_birds$date)[1] "character"
Although the dates are legible to us, R recognizes them as characters. The problem with this is that we cannot order our observations chronologically until R sees date as a true date.
To fix this, we will use the as.Date function. Because the dates are stored as “YYYY-MM-DD” (i.e., four digit year, two digit month, two digit day), we will specify the format argument in as.Date with "%Y-%m-%d", telling R exactly how to read them.
my_birds <- my_birds |>
mutate(date = as.Date(date, format = "%Y-%m-%d")) |>
# arrange by date (newest sighting to oldest sighting)
arrange((desc(date)))Notice below that the dates appear the same visually, but that R now interprets them as “double.” This is what permits the arrange function to correctly order our observations by date.
head(my_birds$date)[1] "2026-10-31" "2026-10-31" "2026-10-31" "2026-10-31" "2026-10-31"
[6] "2026-10-31"
typeof(my_birds$date)[1] "double"
eBird Taxonomy
Now that your eBird data are prepared, we can enrich those observations using the rebird package. While the previous section focused on importing and cleaning our personal bird observations, we now supplement these data with information from eBird’s broader database.
Specifically, we will use eBird’s taxonomy to match our observations to standardized species names, species codes, and taxonomic classifications. We will also use each species’ unique eBird species code to construct a direct link to its species page on the eBird website. These additions will help us explore our observations, learn more about the species we have encountered, and connect our data to eBird’s broader resources.
eBird API
The rebird package accesses your bird observation data through the eBird Application Programming Interface (API). An API is a way for one computer program to request data from another program. In this case, R sends a request to eBird and receives bird observation data directly. To make these requests, however, you will need an eBird API Key. API keys are free and are linked to your eBird account.
You can obtain a free eBird API key here. This will bring you to the following page:
Complete the form and click Submit Request. Your API key will be displayed on the next page.
Copy your API key. We will now install it into our R environment using the edit_r_environ function (part of the usethis package).
# open `.Renviron` file
edit_r_environ()Running edit_r_environ will open the .Renviron file, which stores variables that R reads when it starts. You can think of this file as a place to save settings that you want R to remember across sessions. We will use it to store our eBird API key so that R can access it automatically when making API requests.
When the .Renviron file opens, add the following line (replacing “YOUR_KEY” with the API provided by eBird): EBIRD_KEY='YOUR_KEY'
Save and close the .Renviron file, then restart R for the change to take effect. After restarting, you can confirm that this worked by running Sys.getenv("EBIRD_KEY"), which will print your eBird API key in the console.
Sys.getenv("EBIRD_KEY")rebird
Now that your API key is installed, you can use the rebird package to request taxonomy data. We will do this using the ebirdtaxonomy function, which loads eBird’s full taxonomic reference table (nearly 20,000 observations).
# eBird taxonomy
taxonomy <- ebirdtaxonomy()Because these data reflect all data maintained by eBird, we will first filter it to the birds that appear in our personal data (i.e., my_birds). Use the filter function and tell R to filter taxonomy down to the observations where comName (bird names in taxonomy) are also found in the name column of our data (my_birds$name).
# filter eBird taxonomy to your birds
taxonomy <- taxonomy |>
filter(comName %in% my_birds$name)Next, let’s grab the specific variables that we want from taxonomy, which include comName, speciesCode, and familyComName. Here, too, we will rename these variables directly inside the select function.
# select variables we want
taxonomy <- taxonomy |>
select(name = comName,
ebird_species_code = speciesCode,
fam_common_name = familyComName)Finally, we will use the ebird_species_code variable to create bird-specific links to their eBird page. The species codes that are provided within taxonomy reflect how each species is internally referenced by eBird. For instance, the Black-capped Chickadee’s species code is bkcchi.
# black-capped chickadee species code
taxonomy |> filter(name == "Black-capped Chickadee") |> pull(ebird_species_code)[1] "bkcchi"
Similarly, the Northern Flicker’s species code is norfli.
# northern flicker species code
taxonomy |> filter(name == "Northern Flicker") |> pull(ebird_species_code)[1] "norfli"
These codes are useful because they allow us to construct direct links to individual species pages on eBird. The base URL - https://ebird.org/species/ - is combined with each bird’s unique species code to create its webpage. For example, the Black-capped Chickadee’s page is located at https://ebird.org/species/bkcchi, while the Northern Flicker’s page is at https://ebird.org/species/norfli.
Because this pattern holds for every bird on eBird, we can use the paste0 function to append each bird’s species code to the base URL, generating a link to each bird’s eBird page.
# create link to each species' eBird page
taxonomy <- taxonomy |>
mutate(ebird_url = paste0("https://ebird.org/species/", ebird_species_code))And finally, we join these taxonomy data with our bird observations (my_birds).
my_birds <- my_birds |> left_join(taxonomy, by = "name")Mapping
Now that our bird observations are cleaned, we can visualize the data on an interactive map using the leaflet package. leaflet allows us to pan, zoom, and explore geographic data in a web browser.
Preparing the Data
Before creating the map, we need to prepare our data for display in the map’s “popups” (i.e., the small window that appears when a user clicks a marker on the map). These popups provide details about the bird observations associated with each location.
However, because multiple birds may share the same geographic coordinates, we must first group the observations by latitude, longitude, and location so that each location has a single marker and its popup can display all associated bird observations.
Within each group, we combine each bird’s name, observation date, and link to its eBird species page (ebird_url) into a single string (obs_info). We then combine obs_info with location to create the popup content. To accommodate locations with many observations, we limit the height of the bird list and enable vertical scrolling. A horizontal divider separates the list of observations from the location name, which appears at the bottom of the popup.
# prepare data for mapping
map_data <- my_birds |>
# group by location so all birds at the same coordinates share one marker
group_by(latitude, longitude, location) |>
summarize(
# combine each bird's name, observation date, and eBird link
obs_info = paste0("<b>", name, "</b><br>",
format(date, "%b %d, %Y"), "<br>",
"<a href='", ebird_url,
"' target='_blank'>View on eBird</a><br><br>",
collapse = ""),
# combine bird information (`obs_info`) and `location` into a single column (`popup`)
popup = paste0(
# limit the bird list's height and enable vertical scrolling
"<div style='max-height: 300px; overflow-y: auto;'>",
# observation information
obs_info,
# close the scrollable container
"</div>",
# add a divider between the bird list and location
"<hr style='border: none; border-top: 3px solid #666; margin: 6px 0;'>",
# display the location at the bottom of the popup
"<i>", first(location), "</i>"
)
)Creating the Map
With the data prepared, we can build the interactive map. We begin by passing our prepared data (map_data) to the leaflet function. We then add several layers to the map, each of which contributes a different element to the final visualization.
First,
addProviderTiles("OpenStreetMap")adds a background map using tiles from OpenStreetMap. These tiles provide geographic context, including roads, place names, and other features that help us interpret where our observations occurred.Next,
addMarkersplots a marker for each bird observation. We use the longitude and latitude variables to determine where each marker appears on the map.We can also customize how these markers appear using the
makeIconfunction. Here, I use a bird icon using an image file I created. This file can be downloaded here.The
iconWidth,iconHeight,iconAnchorX, andiconAnchorYarguments control the icon’s size and the point that is anchored to the geographic coordinates. Here, we use a 32-by-32-pixel icon and anchor it near its center so that the marker indicates the observation location.
Finally, we add a popup display to each marker using the
popupargument. When a user clicks a marker, a popup display appears and reveals the bird(s) recorded at that location, their observation dates, and links to their respective eBird pages.
Together, these steps transform our bird observations into an interactive map that connects each species to its geographic location, observation history, and taxonomic information.
# interactive map
map_data |>
# generate map
leaflet() |>
# add background
addProviderTiles("OpenStreetMap") |>
# add markers for observation locations
addMarkers(
# reference `longitude` column
lng = ~longitude,
# reference `latitude` column
lat = ~latitude,
# reference icon for marker
icon = makeIcon(iconUrl = "solid_bird.png",
iconWidth = 32,
iconHeight = 32,
iconAnchorX = 16,
iconAnchorY = 16),
# reference `popup` column (created above)
popup = ~popup
)