Figure 3
library(ggplot2)
library(dplyr)
data <- data.frame(
Biome = c("Prairie", "Bird Garden", "Savanna"),
N = c(0, 0.333, 0.222),
P = c(0.556, 0.556, 0.444),
K = c(1.667, 1.778, 1.667),
pH = c(6.9, 7.1, 7.1)
)
library(tidyr)
data_long <- pivot_longer(data, cols = c(N, P, K, pH), names_to = "Nutrient", values_to = "Level")
nutrient_order <- c("N", "P", "K", "pH")
data_long$Nutrient <- factor(data_long$Nutrient, levels = nutrient_order)
data_long <- data_long %>%
mutate(
Rescaled_pH = ifelse(Nutrient == "pH", (Level - min(Level)) * (2 / (max(Level) - min(Level))), Level),
Label = ifelse(Nutrient == "pH", paste("pH =", Level), paste(Nutrient, "=", Level))
)
graph <- ggplot(data_long, aes(x = Biome, y = Rescaled_pH, fill = Nutrient)) +
geom_bar(stat = "identity", position = "dodge") +
geom_text(aes(label = Label), position = position_dodge(width = 0.9), vjust = -0.5) +
labs(title = “avg_nutrient_levels_pH”, x = "Biome", y = "Level", fill = "Nutrient") +
scale_fill_discrete(name = "Nutrient", labels = c("N", "P", "K", "pH")) +
theme_minimal() +
theme(plot.background = element_rect(fill = "white"))
graph <- graph + scale_y_continuous(
limit = c(0, 2),
sec.axis = sec_axis(~ . * (7.1 / 2), name = "pH")
)
print(graph)
ggsave("avg_nutrient_levels_pH", plot = graph, width = 8, height = 6)
Figure 4a
library(ggplot2)
library(dplyr)
data <- data.frame(
N_prairie = c(0, 0, 0, 0, 0, 0, 0, 0, 0),
N_bird_garden = c(1, 1, 0, 0, 0, 1, 0, 0, 0),
N_savanna = c(1, 0, 0, 0, 0, 0, 0, 1, 0)
)
data_long <- data.frame(
group = rep(names(data), each = nrow(data)),
value = c(as.vector(data$N_prairie), as.vector(data$N_bird_garden), as.vector(data$N_savanna))
)
mean_conf_int <- data_long %>%
group_by(group) %>%
summarize(mean_value = mean(value),
lower_ci = mean_value - 1.96 * sd(value) / sqrt(n()),
upper_ci = mean_value + 1.96 * sd(value) / sqrt(n()))
ggplot() +
geom_bar(data = mean_conf_int, aes(x = group, y = mean_value, fill = group),
stat = "identity", position = position_dodge(width = 0.6), width = 0.5) +
geom_errorbar(data = mean_conf_int, aes(x = group, ymin = lower_ci, ymax = upper_ci),
position = position_dodge(width = 0.6), width = 0.25, color = "black") +
geom_point(data = data_long, aes(x = group, y = value, fill = group),
position = position_jitter(w = 0.4, h = 0, seed = 57), size = 3, shape = 21, color = "black") +
labs(title = "avg_N_values",
x = "biomes", y = "levels") +
theme_minimal() +
scale_fill_manual(values = c("red", "green", "orange")) +
scale_color_manual(values = c("red", "green", "orange"))
Figure 4b
library(ggplot2)
library(dplyr)
data <- data.frame(
P_prairie = c(1, 1, 1, 0.5, 0, 0, 0.5, 0, 1),
P_bird_garden = c(2, 2, 1, 0, 0, 0, 0, 0, 0),
P_savanna = c(1, 0, 1, 1, 1, 0, 0, 0, 0)
)
data_long <- data.frame(
group = rep(names(data), each = nrow(data)),
value = c(as.vector(data$P_prairie), as.vector(data$P_bird_garden), as.vector(data$P_savanna))
)
mean_conf_int <- data_long %>%
group_by(group) %>%
summarize(mean_value = mean(value),
lower_ci = mean_value - 1.96 * sd(value) / sqrt(n()),
upper_ci = mean_value + 1.96 * sd(value) / sqrt(n()))
graph <- ggplot() +
geom_bar(data = mean_conf_int, aes(x = group, y = mean_value, fill = group),
stat = "identity", position = position_dodge(width = 0.6), width = 0.5) +
geom_errorbar(data = mean_conf_int, aes(x = group, ymin = lower_ci, ymax = upper_ci),
position = position_dodge(width = 0.6), width = 0.25, color = "black") +
geom_point(data = data_long, aes(x = group, y = value, fill = group),
position = position_jitter(w = 0.4, h = 0, seed = 69), size = 3, shape = 21, color = "black") +
labs(title = "avg_P_values",
x = "biomes", y = "levels") +
theme_minimal() +
scale_fill_manual(values = c("red", "green", "orange")) +
scale_color_manual(values = c("red", "green", "orange")) +
theme(plot.background = element_rect(fill = "white"))
# plot(graph)
ggsave("avg_P_values.png", plot = graph, width = 8, height = 6)
Figure 4c
library(ggplot2)
library(dplyr)
data <- data.frame(
K_prairie = c(1, 1, 1, 2, 2, 3, 0, 1, 1),
K_bird_garden = c(2, 2, 4, 3, 2, 3, 0, 0, 0),
K_savanna = c(3, 3, 4, 1, 1, 3, 0, 0, 0)
)
data_long <- data.frame(
group = rep(names(data), each = nrow(data)),
value = c(as.vector(data$K_prairie), as.vector(data$K_bird_garden), as.vector(data$K_savanna))
)
mean_conf_int <- data_long %>%
group_by(group) %>%
summarize(mean_value = mean(value),
lower_ci = mean_value - 1.96 * sd(value) / sqrt(n()),
upper_ci = mean_value + 1.96 * sd(value) / sqrt(n()))
graph <- ggplot() +
geom_bar(data = mean_conf_int, aes(x = group, y = mean_value, fill = group),
stat = "identity", position = position_dodge(width = 0.6), width = 0.5) +
geom_errorbar(data = mean_conf_int, aes(x = group, ymin = lower_ci, ymax = upper_ci),
position = position_dodge(width = 0.6), width = 0.25, color = "black") +
geom_point(data = data_long, aes(x = group, y = value, fill = group),
position = position_jitter(w = 0.4, h = 0, seed = 57), size = 3, shape = 21, color = "black") +
labs(title = "avg_K_values",
x = "biomes", y = "levels") +
theme_minimal() +
scale_fill_manual(values = c("red", "green", "orange")) +
scale_color_manual(values = c("red", "green", "orange")) +
theme(plot.background = element_rect(fill = "white"))
# plot(graph)
ggsave("avg_K_values.png", plot = graph, width = 8, height = 6)
Figure 6
library(ggplot2)
library(dplyr)
data <- data.frame(
Biome = c("Bird Garden", "Prairie", "Savanna"),
N = c(1, 0, 0.25),
P = c(1.333, 0.667, 0.5),
K = c(2.333, 1.667, 2.5),
pH = c(7.0, 7.0, 7.0)
)
library(tidyr)
data_long <- pivot_longer(data, cols = c(N, P, K, pH), names_to = "Nutrient", values_to = "Level")
nutrient_order <- c("N", "P", "K", "pH")
data_long$Nutrient <- factor(data_long$Nutrient, levels = nutrient_order)
data_long <- data_long %>%
mutate(
Rescaled_pH = ifelse(Nutrient == "pH", (Level - min(Level)) * (2.5 / (max(Level) - min(Level))), Level),
Label = ifelse(Nutrient == "pH", paste("pH =", Level), paste(Nutrient, "=", Level))
)
graph <- ggplot(data_long, aes(x = Biome, y = Rescaled_pH, fill = Nutrient)) +
geom_bar(stat = "identity", position = "dodge") +
geom_text(aes(label = Label), position = position_dodge(width = 0.9), vjust = -0.5) +
labs(title = "avg_nutrient_pH_pitfall", x = "Biome", y = "Level", fill = "Nutrient") +
scale_fill_discrete(name = "Nutrient", labels = c("N", "P", "K", "pH")) +
theme_minimal() +
theme(plot.background = element_rect(fill = "white"))
graph <- graph + scale_y_continuous(
limit = c(0, 2.5),
sec.axis = sec_axis(~ . * (7.0 / 2.5), name = "pH")
)
print(graph)
ggsave("avg_nutrient_pH_pitfall.png", plot = graph, width = 8, height = 6)
Figure 7a, b
library(ggplot2)
library(readxl)
excel_file_path <- "C:\\Users\\G4\\Desktop\\pitfall_trap_data.xlsx"
data <- read_excel(excel_file_path)
heatmap_plot <- ggplot(data, aes(x = Macroinvertebrate_family, y = Biome, fill = Count)) +
geom_tile() +
labs(title = "macroinvertebrate_count_across_biomes",
x = "macroinvertebrate_family",
y = "biome",
fill = "count") +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "right",
panel.background = element_rect(fill = "white"),
plot.background = element_rect(fill = "white")
)
# head(data)
ggsave("pitfall_trap_heatmap_corrected.png", plot = heatmap_plot, width = 10, height = 6)
Figure 8
library(ggplot2)
library(readxl)
library(tidyr)
excel_file_path <- "C:\\Users\\G4\\Desktop\\ugh.xlsx"
data <- read_excel(excel_file_path)
data_long <- pivot_longer(data, cols = c("N", "P", "K"), names_to = "Nutrient", values_to = "Value")
violin_plot <- ggplot(data_long, aes(x = Nutrient, y = Value, fill = Macroinvertebrate_family)) +
geom_violin(trim = TRUE, alpha = 0.5, position = position_dodge(width = 0.9)) +
labs(title = "distrbution_of_macroinvertebrate_families_with_respect_to_nutrient_level",
x = "nutrient",
y = "level") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
panel.background = element_rect(fill = "white"),
plot.background = element_rect(fill = "white")
)
ggsave("violin_plot.png", plot = violin_plot, width = 10, height = 6)