@@ -8,13 +8,13 @@ library(ggpubr) # For publication-ready themes in ggplot2
88# ------------------------------------------------------------
99
1010# Set working directory to the path where the project files are stored
11- setwd(" /fs/ess/PAS2136/Hawaii-2025/ beetles_intake/ " )
11+ setwd(" /user/ beetles_intake" ) # path anonymized
1212
1313# Define NEON data product ID for beetle data
1414Beetle_dpID <- " DP1.10022.001"
1515
1616# Load NEON API token for accessing the data
17- NEON_TOKEN <- read.delim(" /users/PAS2136/alyeast/Beetle/QC/NEON_Token_AE " , header = FALSE )[1 , 1 ] # Read in the NEON API token
17+ NEON_TOKEN <- read.delim(" /user/Token " , header = FALSE )[1 , 1 ] # Read in the NEON API token path anonymized
1818
1919# Load the beetle data from NEON API using the 'neonUtilities' package
2020NEON_df <- neonUtilities :: loadByProduct(
@@ -123,7 +123,7 @@ unique_beetle$scientificName <- factor(unique_beetle$scientificName,
123123 levels = names(sort(table(unique_beetle $ scientificName ), decreasing = FALSE )))
124124
125125# Create a bar plot for species abundance in the PUUM dataset
126- png(" /users/PAS2136/alyeast/Beetle/DataVis /BeetlePUUM_abundance.png" , width = 10 , height = 5 , units = " in" , res = 300 ) # Set output file and resolution
126+ png(" . /BeetlePUUM_abundance.png" , width = 10 , height = 5 , units = " in" , res = 300 ) # Set output file and resolution
127127ggplot(data = unique_beetle , aes(x = scientificName )) + # Create bar plot for scientificName (species)
128128 geom_bar() + # Add bars for the count of each species
129129 geom_text(stat = ' count' , aes(label = ..count.. ), hjust = - 0.3 , size = 3 , angle = 90 ) + # Add count labels above the bars
@@ -158,7 +158,7 @@ total_counts <- combined_data_merge %>%
158158 group_by(scientificName.x ) %> %
159159 summarise(total = n(), .groups = " drop" )
160160
161- png(" /users/PAS2136/alyeast/Beetle/DataVis /BeetlePUUM_abundance.png" , width = 6.5 , height = 4 , units = " in" , res = 300 ) # Set output file and resolution
161+ png(" . /BeetlePUUM_abundance.png" , width = 6.5 , height = 4 , units = " in" , res = 300 ) # Set output file and resolution
162162ggplot(data = combined_data_merge , aes(x = scientificName.x , fill = imaged )) +
163163 geom_bar() +
164164 geom_text(data = total_counts , aes(x = scientificName.x , y = total , label = total ),
@@ -215,7 +215,7 @@ dim(table(meta_Plooza$genus_spp))/dim(table(all$scientificName))
215215dim(table(meta_Plooza $ NEON_sampleID ))/ dim(table(all $ sampleID ))
216216
217217# Create a bar plot for species abundance in the BeetlePalooza dataset
218- png(" /users/PAS2136/alyeast/Beetle/DataVis /BeetlePalooza_abundance.png" , width = 10 , height = 10 , units = " in" , res = 300 )# Set output file and resolution
218+ png(" . /BeetlePalooza_abundance.png" , width = 10 , height = 10 , units = " in" , res = 300 )# Set output file and resolution
219219ggplot(data = meta_Plooza , aes(x = genus_spp )) + # Create bar plot for genus_species (combined genus and species)
220220 geom_bar(fill = " #ba1419" ) + # Add bars for the count of each genus_species combination
221221 geom_text(stat = ' count' , aes(label = ..count.. ), hjust = - 0.3 , size = 3 ) + # Add count labels above the bars
@@ -239,7 +239,7 @@ all$spp_imaged <- ifelse(
239239# (optional) turn into a factor with a consistent ordering
240240all $ spp_imaged <- factor (all $ spp_imaged , levels = c(" unimaged" ," imaged" ))
241241
242- png(" /users/PAS2136/alyeast/Beetle/DataVis /BeetlePalooza_NEON_abundance.png" , width = 5 , height = 4 , units = " in" , res = 300 )# Set output file and resolution
242+ png(" . /BeetlePalooza_NEON_abundance.png" , width = 5 , height = 4 , units = " in" , res = 300 )# Set output file and resolution
243243ggplot(data = all , aes(x = scientificName , fill = spp_imaged )) + # Create bar plot for genus_species (combined genus and species)
244244 geom_bar() + # Add bars for the count of each genus_species combination
245245# geom_text(stat='count', aes(label = ..count..), hjust = -0.3, size = 3) + # Add count labels above the bars
@@ -270,7 +270,7 @@ img_spp_key<-as.data.frame(img_spp_key[,c("ImageFileName","Species")])
270270img_spp_key $ file <- paste0(" IMG_" ,substr(img_spp_key $ ImageFileName , 5 ,nchar(img_spp_key $ ImageFileName ))," .JPG" )
271271
272272# Read in file with body sizes from annotations
273- body_size <- read.csv(" /fs/ess/PAS2136/Hawaii-2025/beetles_intake /BeetlePUUM/Annotations/traits_metadata.csv" )
273+ body_size <- read.csv(" . /BeetlePUUM/Annotations/traits_metadata.csv" )
274274head(body_size )
275275head(img_spp_key )
276276body_size $ toras_path <- paste0(substr(body_size $ ImageFilePath , 14 , (nchar(body_size $ ImageFilePath )- 4 ))," .JPG" )
@@ -284,7 +284,7 @@ species_counts <- table(body_size$Species)
284284legend_labels <- paste0(names(species_counts ), " (n=" , species_counts , " )" )
285285names(legend_labels ) <- names(species_counts ) # Assign species as names
286286
287- png(" /users/PAS2136/alyeast/Beetle/DataVis /PUUM_bodysize_all.png" , width = 12 , height = 6 , units = " in" , res = 300 )# Set output file and resolution
287+ png(" . /PUUM_bodysize_all.png" , width = 12 , height = 6 , units = " in" , res = 300 )# Set output file and resolution
288288ggplot(data = body_size , aes(x = cm_elytra_max_length , fill = Species )) +
289289 geom_density(alpha = 0.5 ) +
290290 xlab(" Elytra Length (cm)" ) +
@@ -300,7 +300,7 @@ body_size_NEON<-merge(body_size, combined_data, by="individualID", all.x = TRUE,
300300
301301body_size_NEON <- subset(body_size_NEON , plotID != " PUUM_016" )
302302
303- png(" /users/PAS2136/alyeast/Beetle/DataVis /PUUM_bodysize_all.png" , width = 12 , height = 6 , units = " in" , res = 300 )# Set output file and resolution
303+ png(" . /PUUM_bodysize_all.png" , width = 12 , height = 6 , units = " in" , res = 300 )# Set output file and resolution
304304ggplot(data = body_size_NEON , aes(x = cm_elytra_max_length , fill = scientificName )) +
305305 geom_density(alpha = 0.5 ) +
306306 xlab(" Elytra Length (cm)" ) +
@@ -318,12 +318,12 @@ legend <- get_legend(density_plot)
318318
319319library(grid )
320320library(gridExtra )
321- png(" /users/PAS2136/alyeast/Beetle/DataVis /PUUM_bodysize_legend.png" , width = 2.5 , height = 4 , units = " in" , res = 300 , bg = " transparent" )# Set output file and resolution
321+ png(" . /PUUM_bodysize_legend.png" , width = 2.5 , height = 4 , units = " in" , res = 300 , bg = " transparent" )# Set output file and resolution
322322grid.newpage()
323323grid.draw(legend )
324324dev.off()
325325
326- png(" /users/PAS2136/alyeast/Beetle/DataVis /PUUM_bodysize_all_wrap_4.png" , width = 9 , height = 9 , units = " in" , res = 300 )# Set output file and resolution
326+ png(" . /PUUM_bodysize_all_wrap_4.png" , width = 9 , height = 9 , units = " in" , res = 300 )# Set output file and resolution
327327ggplot(data = body_size_NEON , aes(x = cm_elytra_max_length , fill = scientificName )) +
328328 geom_density(alpha = 0.5 ) +
329329 xlab(" Elytra Length (cm)" ) +
@@ -342,7 +342,7 @@ Plot_locations<-as.data.frame(Plot_locations)
342342Plot_locations <- Plot_locations [- c(10 ),]
343343Plot_locations
344344
345- write.csv(Plot_locations , " /users/PAS2136/alyeast/Beetle/DataVis /Plot_locations.csv" )
345+ write.csv(Plot_locations , " . /Plot_locations.csv" )
346346
347347# 2. Subset to species with >10 individuals
348348species_to_keep <- names(species_counts [species_counts > 10 ])
@@ -368,7 +368,7 @@ body_size<-subset(body_size, length_cm>0)
368368
369369
370370# 5. Plot
371- png(" /users/PAS2136/alyeast/Beetle/DataVis /PUUM_bodysize.png" , width = 12 , height = 6 , units = " in" , res = 300 )# Set output file and resolution
371+ png(" . /PUUM_bodysize.png" , width = 12 , height = 6 , units = " in" , res = 300 )# Set output file and resolution
372372ggplot(data = body_size_filtered , aes(x = length_cm , fill = Species )) +
373373 geom_density(alpha = 0.5 ) +
374374 xlab(" Elytra Length (cm)" ) +
@@ -379,7 +379,7 @@ dev.off()
379379
380380
381381min(body_size $ length_cm )
382- png(" /users/PAS2136/alyeast/Beetle/DataVis /PUUM_bodysize_all.png" , width = 10 , height = 10 , units = " in" , res = 300 )# Set output file and resolution
382+ png(" . /PUUM_bodysize_all.png" , width = 10 , height = 10 , units = " in" , res = 300 )# Set output file and resolution
383383ggplot(data = body_size , aes(x = length_cm , fill = Species )) +
384384 geom_density(alpha = 0.5 ) +
385385 theme_pubr() + # Apply publication-style theme
@@ -420,4 +420,4 @@ site_summary<-as.data.frame(site_summary)
420420site_summary <- rbind(site_summary , c(" PUUM" , n_distinct(unique_beetle $ Species ), nrow(unique_beetle )))
421421tail(site_summary )
422422
423- write.csv(site_summary , " /users/PAS2136/alyeast/Beetle/DataVis /site_summary.csv" )
423+ write.csv(site_summary , " . /site_summary.csv" )
0 commit comments