Last active
January 14, 2022 13:31
-
-
Save mikkohei13/0cd013ec1c0d121c53f4131226676ca0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Code courtesy of William Morris | |
| # Requires setting your personal token, and installing this: | |
| # apt-get install libcurl4-openssl-dev libssl-dev | |
| install.packages("finbif") | |
| install.packages("ggplot2") | |
| library(finbif) | |
| library(ggplot2) | |
| Sys.setenv(FINBIF_ACCESS_TOKEN = "<YOUR-PERSONAL-TOKEN>") | |
| get_docs_by_berry_class <- function(x) { | |
| ans <- fb_occurrence( | |
| filter = list( | |
| coordinates = list( | |
| lat = c(61.31, 63.12), lon = c(23.86, 27.68), system = "wgs84" | |
| ), | |
| collection = "Winter Bird Census", | |
| date_range_ymd = c("1986-12-01", "2022-01-31"), | |
| date_range_md = c("12-01", "01-31"), | |
| event_fact = sprintf( | |
| "WBC.sorbusBerriesAtCensus=WBC.berriesAndConesEnum%s", x | |
| ) | |
| ), | |
| select = c("year", "month", "document_id"), | |
| aggregate = "events", | |
| n = "all" | |
| ) | |
| ans$class <- factor(x, 6:1) | |
| subset(ans, select = -c(document_id, n_events)) | |
| } | |
| berries <- lapply(6:1, get_docs_by_berry_class) | |
| berries <- do.call(rbind, berries) | |
| berries$year <- ifelse(berries$month == 1, berries$year - 1, berries$year) | |
| berries <- as.data.frame(table(berries$class, berries$year)) | |
| names(berries) <- c("Runsausluokka", "Talvi", "Osuus") | |
| ggplot(berries) + | |
| aes(fill = Runsausluokka, y = Osuus, x = Talvi) + | |
| geom_bar(position = "fill", stat = "identity") + | |
| scale_fill_grey() + | |
| theme_bw() + | |
| theme(axis.text.x = element_text(angle = 90)) | |
| ggsave("plot.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment