Created
January 9, 2018 09:37
-
-
Save dill/2d8ce38cdcc33be162bab549c81fd5db to your computer and use it in GitHub Desktop.
make an eBird species discovery curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### species discovery curve from eBird | |
library(lubridate) | |
# life list | |
life <- read.csv("ebird_world_life_list.csv") | |
life$date <- lubridate::dmy(as.character(life$Date)) | |
#sort | |
life <- life[order(life$date),] | |
life$num <- 1:nrow(life) | |
# year list | |
year <- read.csv("ebird_WORLD_year_list.csv") | |
year$date <- lubridate::dmy(as.character(year$Date)) | |
#sort | |
year <- year[order(year$date),] | |
year$num <- 1:nrow(year) | |
# when was I where? | |
travel <- rbind( | |
c("1-1-17", "17-1-2017", "UK"), | |
c("18-1-2017", "10-2-2017", "MA"), | |
c("11-2-2017", "14-2-2017", "IA"), | |
c("15-2-2017", "16-3-2017", "MA"), | |
c("17-3-2017", "27-3-2017", "UK"), | |
c("28-3-2017", "5-5-2017", "MA"), | |
c("5-5-2017", "18-5-2017", "SL/IT"), | |
c("19-5-2017", "8-6-2017", "UK"), | |
c("9-6-2017", "15-7-2017", "AU"), | |
c("16-7-2017", "18-8-2017", "UK"), | |
c("19-8-17", "28-8-2017", "IC"), | |
c("29-8-17", "10-9-2017", "UK"), | |
c("10-9-17", "14-9-2017", "NO"), | |
c("15-9-2017", "26-9-2017", "UK"), | |
c("27-9-2017", "1-10-2017", "RI"), | |
c("2-10-2017", "19-10-2017", "UK"), | |
c("20-10-2017", "28-10-2017", "NS"), | |
c("29-10-2017", "2-11-2017", "MA"), | |
c("3-11-2017", "16-11-2017", "UK"), | |
c("17-11-2017", "29-11-2017", "WA"))#, | |
# c("", "", ""), | |
travel <- as.data.frame(travel) | |
names(travel) <- c("start", "end", "place") | |
travel$start <- dmy(travel$start) | |
travel$end <- dmy(travel$end) | |
travel$y <- travel$yend <- 0 | |
library(ggplot2) | |
gg <- ggplot() + | |
geom_line(aes(x=date, y=num), data=life) + | |
geom_line(aes(x=date, y=num), data=year, colour="blue") + | |
geom_hline(yintercept=200, colour="blue", linetype=2) + | |
geom_segment(aes(x=start, xend=end, y=y, yend=yend, group=place, colour=place), | |
linetype=1, size=2, | |
# arrow=arrow(type="closed", ends="both", length=unit(0.01, "inches")), | |
data=travel) + | |
scale_fill_brewer(type="qual") + | |
annotate("text", label="200 bird year", | |
x=ymd("2016-04-01"), y=205, colour="blue") + | |
theme_minimal() + | |
lims(x=c(ymd("2016-03-01"), ymd("2017-12-31"))) + | |
labs(y="Number of bird species", x="", colour="Place") | |
print(gg) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment