Last active
March 27, 2020 08:33
-
-
Save milotictanja/cbc48b9aa5fcccd54dcd3754557ca8e0 to your computer and use it in GitHub Desktop.
Western marsh harrier graphs created for the data paper
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
library(dplyr) | |
library(readr) | |
library(lubridate) | |
library(ggplot2) | |
####Read Groningen data#### | |
WMH_GRONINGEN_movebank_gps_accelero <- read_delim("./data/H_GRONINGEN - Western marsh harriers (Circus aeruginosus, Accipitridae) breeding in Groningen (the Netherlands).csv", | |
",", quote = "\"", skip = 0, col_names = TRUE, na = c('','NA'), | |
locale = readr::locale(encoding = "UTF-8", decimal_mark = ".", grouping_mark = "," ), | |
col_types = list(`event-id` = col_double(), | |
visible = col_logical(), | |
timestamp = col_datetime(format = ""), | |
`location-long` = col_double(), | |
`location-lat` = col_double(), | |
`acceleration-raw-x` = col_double(), | |
`acceleration-raw-y` = col_double(), | |
`acceleration-raw-z` = col_double(), | |
`bar:barometric-pressure` = col_double(), | |
`eobs:start-timestamp` = col_datetime(), | |
`external-temperature` = col_double(), | |
`gps:dop` = col_double(), | |
`gps:satellite-count` = col_double(), | |
`gps-time-to-fix` = col_double(), | |
`gps:vdop` = col_double(), | |
`ground-speed` = col_double(), | |
`heading` = col_double(), | |
`height-above-msl` = col_double(), | |
`location-error-numerical` = col_double(), | |
`manually-marked-outlier` = col_logical(), | |
`start-timestamp` = col_datetime(), | |
`tilt-x` = col_double(), | |
`tilt-y` = col_double(), | |
`tilt-z` = col_double(), | |
`vertical-error-numerical` = col_double(), | |
`sensor-type` = col_character(), | |
`individual-taxon-canonical-name` = col_character(), | |
`tag-local-identifier` = col_double(), | |
`individual-local-identifier` = col_double(), | |
`study-name` = col_character())) | |
WMH_GRONINGEN_movebank_ref_data <- read_delim("./data/H_GRONINGEN - Western marsh harriers (Circus aeruginosus, Accipitridae) breeding in Groningen (the Netherlands)-reference-data.csv", | |
",", quote = "\"", skip = 0, col_names = TRUE, na = c('','NA'), | |
locale = readr::locale(encoding = "UTF-8", decimal_mark = ".", grouping_mark = "," ), | |
trim_ws = TRUE, progress = FALSE) | |
# select GPS data | |
WMH_GRONINGEN_movebank_gps <- WMH_GRONINGEN_movebank_gps_accelero %>% | |
filter( !is.na(`location-long`)) | |
# join GPS data and reference data | |
WMH_GRONINGEN_movebank_gps_join <- left_join(WMH_GRONINGEN_movebank_gps, WMH_GRONINGEN_movebank_ref_data, | |
by = c("individual-local-identifier" = "animal-id")) | |
####Read Waterland data#### | |
WMH_WATERLAND_movebank_gps <- read_delim("./data/MH_WATERLAND - Western marsh harriers (Circus aeruginosus, Accipitridae) breeding near the Belgium-Netherlands border.csv", | |
",", quote = "\"", skip = 0, col_names = TRUE, na = c('','NA'), | |
locale = readr::locale(encoding = "UTF-8", decimal_mark = ".", grouping_mark = "," ), | |
col_types = list(`event-id` = col_double(), | |
visible = col_logical(), | |
timestamp = col_datetime(format = ""), | |
`location-long` = col_double(), | |
`location-lat` = col_double(), | |
`algorithm-marked-outlier` = col_logical(), | |
`bar:barometric-height` = col_logical(), | |
`bar:barometric-pressure` = col_double(), | |
`compass-heading` = col_logical(), | |
`external-temperature` = col_double(), | |
`gps:dop` = col_double(), | |
`gps:satellite-count` = col_double(), | |
`gps-time-to-fix` = col_double(), | |
`gps:vdop` = col_double(), | |
`ground-speed` = col_double(), | |
`heading` = col_double(), | |
`height-above-msl` = col_double(), | |
`location-error-numerical` = col_double(), | |
`manually-marked-outlier` = col_logical(), | |
`vertical-error-numerical` = col_double(), | |
`sensor-type` = col_character(), | |
`individual-taxon-canonical-name` = col_character(), | |
`tag-local-identifier` = col_double(), | |
`individual-local-identifier` = col_character(), | |
`study-name` = col_character())) | |
WMH_WATERLAND_movebank_ref_data <- read_delim("./data/MH_WATERLAND - Western marsh harriers (Circus aeruginosus, Accipitridae) breeding near the Belgium-Netherlands border-reference-data.csv", | |
",", quote = "\"", skip = 0, col_names = TRUE, na = c('','NA'), | |
locale = readr::locale(encoding = "UTF-8", decimal_mark = ".", grouping_mark = "," ), | |
trim_ws = TRUE, progress = FALSE) | |
# join GPS data and reference data | |
WMH_WATERLAND_movebank_gps_join <- left_join(WMH_WATERLAND_movebank_gps, WMH_WATERLAND_movebank_ref_data, by = c("individual-local-identifier" = "animal-id")) | |
#####Read Antwerpen data#### | |
WMH_ANTWERPEN_movebank_gps_accelero <- read_delim("./data/MH_ANTWERPEN - Western marsh harriers (Circus aeruginosus, Accipitridae) breeding near Antwerp (Belgium).csv" , | |
",", quote = "\"", skip = 0, col_names = TRUE, na = c('','NA'), | |
locale = readr::locale(encoding = "UTF-8", decimal_mark = ".", grouping_mark = "," ), | |
col_types = list(`event-id` = col_double(), | |
visible = col_logical(), | |
timestamp = col_datetime(format = ""), | |
`location-long` = col_double(), | |
`location-lat` = col_double(), | |
`acceleration-raw-x` = col_double(), | |
`acceleration-raw-y` = col_double(), | |
`acceleration-raw-z` = col_double(), | |
`bar:barometric-pressure` = col_double(), | |
`eobs:start-timestamp` = col_datetime(), | |
`external-temperature` = col_double(), | |
`gps:dop` = col_double(), | |
`gps:satellite-count` = col_double(), | |
`gps-time-to-fix` = col_double(), | |
`gps:vdop` = col_double(), | |
`ground-speed` = col_double(), | |
`heading` = col_double(), | |
`height-above-msl` = col_double(), | |
`location-error-numerical` = col_double(), | |
`manually-marked-outlier` = col_logical(), | |
`start-timestamp` = col_datetime(), | |
`tilt-x` = col_double(), | |
`tilt-y` = col_double(), | |
`tilt-z` = col_double(), | |
`vertical-error-numerical` = col_double(), | |
`sensor-type` = col_character(), | |
`individual-taxon-canonical-name` = col_character(), | |
`tag-local-identifier` = col_double(), | |
`individual-local-identifier` = col_character(), | |
`study-name` = col_character())) | |
WMH_ANTWERPEN_movebank_ref_data <- read_delim("./data/MH_ANTWERPEN - Western marsh harriers (Circus aeruginosus, Accipitridae) breeding near Antwerp (Belgium)-reference-data.csv", | |
",", quote = "\"", skip = 0, col_names = TRUE, na = c('','NA'), | |
locale = readr::locale(encoding = "UTF-8", decimal_mark = ".", grouping_mark = "," ), | |
trim_ws = TRUE, progress = FALSE) | |
# select GPS data | |
WMH_ANTWERPEN_movebank_gps <- WMH_ANTWERPEN_movebank_gps_accelero %>% | |
filter( !is.na(`location-long`)) | |
# join GPS data and reference data | |
WMH_ANTWERPEN_movebank_gps_join <- left_join(WMH_ANTWERPEN_movebank_gps, WMH_ANTWERPEN_movebank_ref_data, | |
by = c("individual-local-identifier" = "animal-id")) | |
####Graphs#### | |
# select relevant columns | |
WMH_GRONINGEN_temp <- WMH_GRONINGEN_movebank_gps_join[,c('tag-id', 'height-above-msl', 'location-long', 'location-lat', 'external-temperature', | |
'timestamp', 'animal-sex', 'animal-nickname', 'animal-life-stage', 'animal-mass')] | |
WMH_WATERLAND_temp <- WMH_WATERLAND_movebank_gps_join[,c('tag-id', 'height-above-msl', 'location-long', 'location-lat', 'external-temperature', | |
'timestamp', 'animal-sex', 'animal-nickname', 'animal-life-stage', 'animal-mass')] | |
WMH_ANTWERPEN_temp <- WMH_ANTWERPEN_movebank_gps_join[,c('tag-id', 'height-above-msl', 'location-long', 'location-lat', 'external-temperature', | |
'timestamp', 'animal-sex', 'animal-nickname', 'animal-life-stage', 'animal-mass')] | |
# add dataset name | |
WMH_GRONINGEN_temp$dataset <- rep("H_GRONINGEN", nrow(WMH_GRONINGEN_temp)) | |
WMH_WATERLAND_temp$dataset <- rep("MH_WATERLAND", nrow(WMH_WATERLAND_temp)) | |
WMH_ANTWERPEN_temp$dataset <- rep("MH_ANTWERPEN",nrow(WMH_ANTWERPEN_temp)) | |
# combine datasets | |
WMH_all <- WMH_GRONINGEN_temp %>% | |
bind_rows(WMH_WATERLAND_temp) %>% | |
bind_rows(WMH_ANTWERPEN_temp) | |
WMH_all$date <- date(WMH_all$timestamp) | |
# Figure 3 - graph with number of tracking effort per individual | |
WMH_all$`animal-nickname` <- as.factor(WMH_all$`animal-nickname`) | |
WMH_all_TE <- WMH_all %>% | |
group_by(date, `animal-nickname`, dataset) %>% | |
count() | |
WMH_all_TE$nickname <- factor(WMH_all_TE$`animal-nickname`, levels = c("Job", "Kjell", "Roelof", "William", "Almut", "Ben", "Jozef", | |
"Mia", "Peter", "Raymond","Walter", "Lilla", "Lillo", "Zuzanna")) | |
WMH_all_TE$dataset <- factor(WMH_all_TE$dataset, levels = c("H_GRONINGEN", "MH_WATERLAND", "MH_ANTWERPEN")) | |
TE_plot <- ggplot(data = WMH_all_TE) + | |
geom_line(aes(x = date, y = n, colour = factor(dataset)), size = 1) + | |
facet_wrap(~ nickname, scales = "free") + | |
theme_minimal() + | |
scale_y_continuous(name = "Tracking effort (observations/day)", expand = c(0,0), limits = c(0, NA), labels = scales::comma, breaks = scales::pretty_breaks()) + | |
scale_x_date(name = "Date", breaks = scales::pretty_breaks(4), labels = scales::date_format("%Y-%m")) + | |
scale_colour_manual(name = "Dataset", values = c("H_GRONINGEN" = "#9ccb86", "MH_WATERLAND" = "#e9e29c", "MH_ANTWERPEN" = "#eeb479"), | |
breaks = c("H_GRONINGEN", "MH_WATERLAND", "MH_ANTWERPEN")) + | |
theme(axis.text = element_text(size = 8), | |
axis.title = element_text(face = "bold", size = 18), | |
legend.text = element_text(size = 14), | |
legend.title = element_text(face = "bold", size = 18), | |
axis.line.x = element_line(size = 0.5), | |
axis.line.y = element_line(size = 0.5), | |
axis.ticks = element_line(size = 0.5), | |
strip.text = element_text(size = 14, hjust = 0), | |
legend.position = c(0.85, 0.075), | |
plot.margin = unit(c(0.5, 1, 0.5, 0.5),"cm")) | |
TE_plot | |
ggsave("fig3_trackingEffort.png", TE_plot) | |
# Figure 4 - graph with number of fixes/year/dataset | |
WMH_all$year <- year(WMH_all$timestamp) | |
WMH_all_fixes <- WMH_all %>% | |
group_by(year, dataset) %>% | |
count() | |
WMH_all_fixes <- WMH_all_fixes %>% | |
group_by((year)) %>% | |
arrange(year, desc(dataset)) %>% | |
mutate(lab_ypos = cumsum(n) - (0.5 * n) + 3000) | |
fixes_plot <- ggplot(WMH_all_fixes, aes(x = year, y = n)) + | |
geom_col(aes(fill = dataset)) + | |
geom_text(aes(y = lab_ypos, x = year, label = scales::comma(n), group = dataset), size = 4, color = "black") + | |
theme_minimal() + | |
theme(axis.line.y = element_blank()) + | |
scale_fill_manual(name = "Dataset", values = c("H_GRONINGEN" = "#9ccb86", "MH_WATERLAND" = "#e9e29c", "MH_ANTWERPEN" = "#eeb479"), | |
breaks = c("H_GRONINGEN", "MH_WATERLAND", "MH_ANTWERPEN")) + | |
scale_x_continuous(name = "Year", breaks = c(2012:2019)) + | |
scale_y_continuous(name = "Number of fixes", limits = c(0, 350000), breaks = c(0, 100000, 200000, 300000), | |
expand = c(0,0), labels = scales::comma) + | |
theme(axis.text = element_text(size = 14), | |
axis.title = element_text(face = "bold", size = 18), | |
legend.text = element_text(size = 14), | |
legend.title = element_text(face = "bold", size = 18), | |
axis.line.x = element_line(size = 0.5)) | |
fixes_plot | |
ggsave("fig4_fixes.png", fixes_plot) | |
#### Figure 5 - graph with accelerometer data#### | |
# select accelerometer data | |
WMH_GRONINGEN_movebank_accelero <- WMH_GRONINGEN_movebank_gps_accelero %>% | |
filter(!is.na(`acceleration-raw-x`)) | |
WMH_ANTWERPEN_movebank_accelero <- WMH_ANTWERPEN_movebank_gps_accelero %>% | |
filter(!is.na(`acceleration-raw-x`)) | |
# make dataset for plotting | |
WMH_GRONINGEN_temp2 <- WMH_GRONINGEN_movebank_accelero[, c('event-id', 'timestamp', 'acceleration-raw-x', 'acceleration-raw-y', | |
'acceleration-raw-z', 'eobs:start-timestamp', 'start-timestamp', | |
'tilt-x', 'tilt-y', 'tilt-z')] | |
WMH_ANTWERPEN_temp2 <- WMH_ANTWERPEN_movebank_accelero[, c('event-id', 'timestamp', 'acceleration-raw-x', 'acceleration-raw-y', | |
'acceleration-raw-z', 'eobs:start-timestamp', 'start-timestamp', | |
'tilt-x', 'tilt-y', 'tilt-z')] | |
WMH_GRONINGEN_temp2$dataset <- rep("H_GRONINGEN", nrow(WMH_GRONINGEN_temp2)) | |
WMH_ANTWERPEN_temp2$dataset <- rep("MH_ANTWERPEN",nrow(WMH_ANTWERPEN_temp2)) | |
WMH_all_accelero <- WMH_GRONINGEN_temp2 %>% | |
bind_rows(WMH_ANTWERPEN_temp2) | |
WMH_all_accelero$year <- year(WMH_all_accelero$timestamp) | |
WMH_all_accelero_plot <- WMH_all_accelero %>% | |
group_by(year, dataset) %>% | |
count() | |
WMH_all_accelero_plot <- WMH_all_accelero_plot %>% | |
group_by((year)) %>% | |
arrange(year, desc(dataset)) %>% | |
mutate(lab_ypos = cumsum(n) - (0.5 * n) + 10000) | |
accelero_plot <- ggplot(WMH_all_accelero_plot, aes(x = year, y = n)) + | |
geom_col(aes(fill = dataset)) + | |
geom_text(aes(y = lab_ypos, x = year, label = scales::comma(n), group = dataset), size = 4, color = "black") + | |
theme_minimal() + | |
theme(axis.line.y = element_blank()) + | |
scale_fill_manual(name = "Dataset", values = c("H_GRONINGEN" = "#9ccb86", "MH_ANTWERPEN" = "#eeb479"), | |
breaks = c("H_GRONINGEN", "MH_ANTWERPEN")) + | |
scale_x_continuous(name = "Year", breaks = c(2012:2019)) + | |
scale_y_continuous(name = "Acceleration records (n)", limits = c(0, 1000000), breaks = c(0, 250000, 500000, 750000), | |
expand = c(0,0), labels = scales::comma) + | |
theme(axis.text = element_text(size = 14), | |
axis.title = element_text(face = "bold", size = 18), | |
legend.text = element_text(size = 14), | |
legend.title = element_text(face = "bold", size = 18), | |
axis.line.x = element_line(size = 0.5)) | |
accelero_plot | |
ggsave("fig5_accelero.png", accelero_plot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment