Authors: Dominik Marchowski, Robert Jurszo, Paweł Stańczak, Michał Jasiński, Sebastain Guentzel
This report presents an analysis of Cranes count data across multiple years and seasons. We calculate average counts and standard errors for selected years, and visualize counts with a box plot.
# Load required libraries
library(ggplot2)
library(tidyr)
The data frame below includes bird counts for each year across three periods in September and October. We then transform it to a long format for easier visualization.
# Creating the data frame with English column names
df <- data.frame(
Period = c("September I", "September II", "October"),
`2019` = c(1106, 2590, 2491),
`2020` = c(1446, 2562, 2632),
`2021` = c(2024, 3676, 1655),
`2022` = c(327, 13, 0),
`2023` = c(365, 654, 559),
`2024` = c(617, 486, 1629),
check.names = FALSE # Prevents automatic renaming of column names
)
# Transforming data to long format
df_long <- pivot_longer(df, cols = -Period, names_to = "Year", values_to = "Count")
# Adding a column specifying highlighted years
df_long$Highlight <- ifelse(df_long$Year %in% c("2021", "2022", "2023"), "Highlighted", "Regular")
# Converting the Year column to a factor to preserve chronological order
df_long$Year <- factor(df_long$Year, levels = unique(df_long$Year))
The following box plot visualizes bird counts across years, with highlighted years displayed in a different color.
# Creating a box plot with highlighted years
p2 <- ggplot(df_long, aes(x = Year, y = Count, fill = Highlight)) +
geom_boxplot(color = "black") +
scale_fill_manual(values = c("Highlighted" = "grey", "Regular" = "white")) +
theme_bw() +
labs(x = "Year", y = "Count") +
theme(
legend.position = "none",
axis.title.x = element_text(size = 14),
axis.title.y = element_text(size = 14),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12)
)
# Display the plot
print(p2)
We calculate the mean count and standard error for the years 2019 and 2020, 2022 and 2023, and for 2024. Each calculation is done separately to illustrate trends over time.
# Data for 2019 and 2020
df_2019_2020 <- data.frame(
Period = c("September I", "September II", "October"),
`2019` = c(1106, 2590, 2491),
`2020` = c(1446, 2562, 2632),
check.names = FALSE
)
counts_2019_2020 <- c(df_2019_2020$`2019`, df_2019_2020$`2020`)
# Calculating mean and SE
mean_counts <- mean(counts_2019_2020, na.rm = TRUE)
se_counts <- sd(counts_2019_2020, na.rm = TRUE) / sqrt(length(counts_2019_2020))
cat("Mean count for 2019 and 2020:", round(mean_counts, 2), "±", round(se_counts, 2), "(SE)\n")
## Mean count for 2019 and 2020: 2137.83 ± 276.68 (SE)
# Data for 2022 and 2023
df_2022_2023 <- data.frame(
Period = c("September I", "September II", "October"),
`2022` = c(327, 13, 0),
`2023` = c(365, 654, 559),
check.names = FALSE
)
counts_2022_2023 <- c(df_2022_2023$`2022`, df_2022_2023$`2023`)
# Calculating mean and SE
mean_counts <- mean(counts_2022_2023, na.rm = TRUE)
se_counts <- sd(counts_2022_2023, na.rm = TRUE) / sqrt(length(counts_2022_2023))
cat("Mean count for 2022 and 2023:", round(mean_counts, 2), "±", round(se_counts, 2), "(SE)\n")
## Mean count for 2022 and 2023: 319.67 ± 110.66 (SE)
# Data for 2024
df_2024 <- data.frame(
Period = c("September I", "September II", "October"),
`2024` = c(617, 486, 1629),
check.names = FALSE
)
counts_2024 <- df_2024$`2024`
# Calculating mean and SE
mean_counts <- mean(counts_2024, na.rm = TRUE)
se_counts <- sd(counts_2024, na.rm = TRUE) / sqrt(length(counts_2024))
cat("Mean count for 2024:", round(mean_counts, 2), "±", round(se_counts, 2), "(SE)\n")
## Mean count for 2024: 910.67 ± 361.15 (SE)
This report provided a visual and statistical summary of Cranes counts across selected years and seasons, highlighting trends and comparing means with associated standard errors for each period.