You have found the documentation for the swedishbirdtrends
package, which distributes Swedish bird populations trend data for use with the R platform. The bundled data comes from http://www.fageltaxering.lu.se/resultat/trender at 2016-02-14.
"Svensk fågeltaxering" monitor the common birds of Sweden since 40 years. Birds are counted in summer and winter at hundreds of different sites. Since the counts are carried out in the same way each year, it is possible to detect which species that increase or decrease in numbers.
The project is carried out at the Department of Biology, Lund University, as a part of a national environmental monitoring project run by The Swedish Environmental Protection Agency and supported by all the 21 County Administrative Boards of Sweden.
The bird counts are mainly carried out by volunteers, and the project is the Swedish representative in the European network for bird monitoring (EBCC).
This example shows how to use the birdtotals
and birdtrends
data bundled in the package.
suppressPackageStartupMessages(library(swedishbirdtrends)) data(birdtotals) data(birdtrends)
You can work with the data in different ways. We recommend using dplyr
and tidyr
- these packages offers better flexibility than many alternatives, such as SQL, especially when it comes to pivoting and using any kind of function you can think of for cleaning data, such as georeferencing etc.
library(dplyr) # filter columns on one or multiple values birds <- birdtotals %>% filter(Series == "Standard") %>% filter(Significance %in% c("*", "**", "***")) # renaming columns trends <- birdtrends %>% select(Art = Arthela, Year, Index = Measure, Rutt = Series)
Here are the first few rows of the extract from birdtotals
displayed as a static table:
knitr::kable(birds %>% head(5))
Here are the first few rows of the extract from birdtrends
displayed as a static table:
knitr::kable(trends %>% head(5))
You can make more advanced extracts. Here we extract some birds that are winners / gainers and some that are losers / on the decline ;) and display these "top ten" lists in tabular formats.
# find the top 20 "winners" and "losers" winners <- birds %>% filter(YPctChg > 0) %>% arrange(desc(YPctChg)) %>% select(Art = Arthela, YPctChg, Ind, Significance) %>% head(10) losers <- birds %>% filter(YPctChg <= 0) %>% arrange(-desc(YPctChg)) %>% select(Art = Arthela, YPctChg, Ind, Significance) %>% head(10)
Here are the first few rows of the rising birds displayed as a table:
knitr::kable(winners %>% head(5))
Here are the first few rows of the declining birds displayed as a table:
knitr::kable(losers %>% head(5))
Packages such as ggplot2
- which can be styled using themes in ggthemes
- can be used to create figures such as horizontal bar graphs or line graphs etc that can be displayed side-by-side.
library(ggplot2) library(ggthemes) plot_w <- ggplot(winners) + aes(x = reorder(Art, YPctChg), y = YPctChg) + geom_bar(stat = "identity") + labs(x = "") + labs(y = "% förändr per år") + theme_economist_white() + coord_flip() plot_l <- ggplot(losers) + aes(x = reorder(Art, YPctChg), y = YPctChg) + geom_bar(stat = "identity") + labs(x = "") + labs(y = "% förändr per år") + theme_wsj() + coord_flip()
Here the plots created above are displayed, using two different styles (from The Economist and Wall Street Journal respectively from left to right):
plot_w plot_l
This are population trend plots for "Glada" and "Koltrast":
glada <- birdtrends %>% filter(Series == "Vinter") %>% filter(Arthela == "Glada") %>% select(Year, Measure, Series) koltrast <- birdtrends %>% filter(Series == "Vinter") %>% filter(Arthela == "Koltrast") %>% select(Year, Measure, Series) red <- RColorBrewer::brewer.pal(3, "PuRd")[3] plot_trend <- function(df, title) { ggplot(df) + aes(x = Year, y = Measure, group = Series) + scale_x_discrete(breaks = c(1975, 1985, 1998, 2005, 2015)) + ylab("Index") + xlab("År") + ggtitle(title) + geom_point(size = 1.2) + #geom_line() + geom_smooth(method = "loess", aes(group = Series, color = red)) + guides(colour = FALSE, size = FALSE) + #scale_color_few() + theme_solarized() } plot_trend(glada, "Glada, Vinterrutt") plot_trend(koltrast, "Koltrast, Vinterrutt")
For convenience, a function is provided that provides static trend plots:
plot_sbt_static("Svarthätta") plot_sbt_static("Svarthätta", loess = TRUE) plot_sbt_static("Brushane", loess = TRUE) plot_sbt_static("Brushane", showlegend = FALSE)
Another function provides dynamic trend plots:
plot_sbt_dy("Brushane") plot_sbt_dy("Svarthätta")
It is possible to provide interactive web applications as part of the package using shiny
. To see a couple of examples of this using the datasets bundled in this package, use the following approach:
# use this to launch the shiny web app examples runShinyApp("birdtrends") runShinyApp("birdtotals")
"Better Ten Birds singing in the Forest than One Jaild Bird" (via)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.