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.

About the data source

"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.

Svensk Fågeltaxering

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).

Lunds Universitet Naturvårdsverket Länsstyrelserna SOF BirdLife EBCC - European Bird Census Council

Using bundled data

This example shows how to use the birdtotalsand 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))

Data wrangling

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))

Creating plots and figures

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()

Plotting with style

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

Static trend plot

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")

Shiny web apps

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")

Finally

Free Birds

"Better Ten Birds singing in the Forest than One Jaild Bird" (via)



mskyttner/swedishbirdtrends documentation built on May 23, 2019, 7:53 a.m.