# Load libraries
library(ggplot2)Warning: package 'ggplot2' was built under R version 4.5.3
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(tidyr)
library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
# Read the CSV file
data <- read.csv("C:/Users/lmkerner/Documents/Tea Arthropod Counts 2025.csv")
# View first few rows
head(data) IDer Date Sample.. Collection.type Araneae Spiderling Lycosidae
1 CMD 10/9/2025 1 flower 0 0 0
2 CMD 10/9/2025 2 flower 0 0 0
3 CMD 10/9/2025 3 flower 0 0 0
4 CMD 10/15/2025 1 flower 0 0 0
5 CMD 10/15/2025 2 flower 0 0 0
6 CMD 10/15/2025 3 flower 0 0 0
Dictynidae Salticidae Thomisidae SpiderEggMass A.mellifera Bombus Halictidae
1 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0
Formicidae L.humile Polistes Carabidae C.maculata D.undecimpunctata
1 0 0 0 0 0 0
2 1 0 0 0 0 0
3 0 0 0 0 0 0
4 1 0 0 0 0 0
5 2 0 0 0 0 0
6 0 0 0 0 0 0
P.vigintimaculata Corylophidae Latridiidae Odontocorynus Calliphoridae
1 0 0 0 0 0
2 0 0 0 0 0
3 0 0 0 0 0
4 0 0 0 0 0
5 0 0 0 0 0
6 0 0 0 0 0
Sarcophagidae Tachinidae Syrphidae Eristalis Palpada Flies Agromyzidae
1 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0
5 0 0 0 0 0 1 0
6 0 0 0 0 0 1 0
Nymphalidae Tortricidae A.aurea LepEggs Malescale Pseudococcidae Ceroplastes
1 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0
Coccidae Driedscale Diaspididae Fiorinia Lepidosaphes Aphidae T.aurantii
1 0 0 0 0 0 8 0
2 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0
Thysanoptera F.occidentalis Thrips Blackthrips T.tabaci PredMite Orangemite
1 3 0 0 0 0 0 0
2 1 0 0 0 0 0 0
3 3 0 0 0 0 0 0
4 30 0 0 0 0 0 0
5 14 0 0 0 0 0 0
6 4 0 0 0 0 0 0
Spidermite Fungusmite Fungusmiteeggs Cicadellidae Pentatomidae N.viridula
1 0 0 0 0 0 0
2 0 0 0 0 0 0
3 0 0 0 0 0 0
4 0 0 0 0 0 0
5 0 0 0 0 0 0
6 0 0 0 0 0 0
Miridae L.lineolaris Orthotylinae Orius Collembola Snail Fuzzywhiteeggs
1 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0
5 0 0 0 1 0 0 0
6 0 0 0 0 0 0 0
Eggmass TinyBlackLarvae1 MysteryEgg1 ElongatedEggMass Notes X
1 0 0 0 0
2 0 0 0 0
3 0 0 0 0
4 0 0 0 0
5 0 0 0 0
6 0 0 0 0
# Clean Collection.type (optional but recommended)
data$Collection.type <- trimws(tolower(data$Collection.type))
# Group by collection type and make cumulative counts
totals_by_collection <- data %>%
group_by(Collection.type) %>%
select(-Sample..) %>%
summarise(
across(where(is.numeric), ~ sum(.x, na.rm = TRUE))
)
# Convert to long format
taxa_long <- totals_by_collection %>%
pivot_longer(
cols = where(is.numeric),
names_to = "Taxa",
values_to = "Count"
)
# Make the bar graph (FACETED + COLORED + VERTICAL LABELS)
p <- ggplot(taxa_long, aes(x = Taxa, y = Count, fill = Taxa)) +
geom_bar(stat = "identity") +
facet_wrap(~ Collection.type, scales = "free_y") +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)
) +
labs(
title = "Arthropod Counts by Taxa and Collection Type",
x = "Taxa",
y = "Total Count"
) +
guides(fill = "none") # removes redundant legend
# Show static plot
p# Make interactive
ggplotly(p)