Tivy
is an R package specialized in processing and
analyzing fisheries data from Peruβs anchovy (Engraulis ringens)
fishery. It facilitates the handling of information from fishing trip
logbooks, size records, hauls, and official announcements issued for
preventive closures.
You can install the development version of Tivy
from
GitHub:
# install.packages("devtools")
::install_github("HansTtito/Tivy") devtools
Install CRAN release:
install.packages("Tivy")
library(Tivy)
# Load and process logbook files
<- process_hauls(
data_hauls data_hauls = calas_bitacora,
correct_coordinates = TRUE,
verbose = TRUE
)
<- process_fishing_trips(
data_fishing_trips data_fishing_trips = faenas_bitacora,
verbose = TRUE
)
<- process_length(
hauls_length data_length = tallas_bitacora,
verbose = TRUE
)
# Combination of length and fishing trip data
<- merge(
data_length_fishing_trips x = data_fishing_trips,
y = hauls_length,
by = 'fishing_trip_code',
all = TRUE
)
# Complete integration with haul data
<- merge_length_fishing_trips_hauls(
data_total data_hauls = data_hauls,
data_length_fishing_trips = data_length_fishing_trips
)
# Add derived variables (juveniles, distance to coast, etc.)
<- add_variables(
final_data data = data_total,
JuvLim = 12, # Juvenile threshold in cm
distance_type = "haversine",
unit = "nm"
)
# Define length columns manually
<- as.character(seq(from = 8, to = 15, by = 0.5))
length_cols
# Length-weight relationship parameters (for anchoveta)
<- 0.0001
a <- 2.983
b
# Create catch column in tons
$catch_t <- final_data$catch_ANCHOVETA / 1000
final_data
# Weight length frequencies according to catch
<- apply_catch_weighting(
final_data_weighted data = final_data,
length_cols = length_cols,
catch_col = 'catch_t',
a = a, # Length-weight coefficient
b = b # Length-weight exponent
)
# Calculate juvenile proportion by group
<- summarize_juveniles_by_group(
juvenile_results data = final_data_weighted,
group_cols = c("dc_cat"), # Distance category
length_cols = paste0("weighted_", length_cols),
juvenile_limit = 12,
a = a,
b = b
)
print(juvenile_results)
# Create date column for plotting
$unique_date <- convert_to_date(final_data_weighted$start_date_haul)
final_data_weighted
# Basic plot of juveniles by date
<- plot_juvenile_analysis(
juvenile_plot data = final_data_weighted,
x_var = "unique_date",
fill_var = "dc_cat",
length_cols = paste0("weighted_", length_cols),
a = a,
b = b,
reference_line = 10
)
print(juvenile_plot)
# Complete dashboard of juvenile analysis
<- create_fishery_dashboard(
dashboard data = final_data_weighted,
date_col = "unique_date",
length_cols = paste0("weighted_", length_cols),
a = a,
b = b,
latitude_col = "lat_initial",
longitude_col = "lon_initial",
catch_col = "catch_t",
juvenile_col = "juv",
date_breaks = "1 day"
)
# View individual dashboard components
$comparison # Juvenile comparison
dashboard$trends # Juvenile trends over time
dashboard$catch_trends # Cumulative catch
dashboard$spatial_map # Spatial distribution map
dashboard$dashboard # Complete panel with all plots dashboard
# Fetch announcements from PRODUCE website
<- fetch_fishing_announcements(
pdf_announcements start_date = "01/03/2025",
end_date = "31/03/2025",
download = FALSE # Set TRUE to download PDF files
)
print(pdf_announcements)
# Extract information from PDF announcements
<- extract_pdf_data(
results pdf_sources = pdf_announcements$DownloadURL
)
# Format data for visualization
<- format_extracted_data(
formatted_results data = results,
convert_coordinates = TRUE
)
# Visualize closed areas with ggplot (static)
<- plot_fishing_zones(
static_plot data = formatted_results,
type = "static",
show_legend = TRUE,
title = "Fishing Closure Areas"
)
print(static_plot)
# Interactive visualization with leaflet
<- plot_fishing_zones(
interactive_map data = formatted_results,
type = "interactive",
show_legend = TRUE,
base_layers = TRUE,
minimap = TRUE
)
interactive_map
process_*()
functionsmerge_length_fishing_trips_hauls()
add_variables()
(distances, juveniles, etc.)apply_catch_weighting()
for biomass analysissummarize_juveniles_by_group()
convert_to_date()
plot_juvenile_analysis()
or
create_fishery_dashboard()
Tivy
is designed to work with fishery data from Peru.
The package includes built-in sample datasets:
calas_bitacora
: Sample haul records
with coordinates and catch datafaenas_bitacora
: Sample fishing trip
informationtallas_bitacora
: Sample length
frequency dataCategory | Functions | Description |
---|---|---|
Data Processing | process_hauls() , process_fishing_trips() ,
process_length() |
Data loading, cleaning, and standardization |
Data Integration | merge_length_fishing_trips_hauls() ,
add_variables() |
Data combination and variable enrichment |
Spatial Analysis | dms_to_decimal() , coast_distance() ,
land_points() |
Coordinate conversion and spatial calculations |
Juvenile Analysis | apply_catch_weighting() ,
summarize_juveniles_by_group() ,
calculate_fish_weight() |
Population structure and juvenile proportion analysis |
Visualization | plot_juvenile_analysis() ,
plot_fishing_zones() ,
create_fishery_dashboard() |
Static and interactive plotting |
Announcements | fetch_fishing_announcements() ,
extract_pdf_data() ,
format_extracted_data() |
Processing of official regulatory announcements |
Utilities | convert_to_date() ,
find_columns_by_pattern() ,
validate_*_data() |
Helper functions and data validation |
Comprehensive documentation is available through vignettes:
# Overview and quick start
vignette("introduction", package = "Tivy")
# Detailed data processing workflows
vignette("data-processing", package = "Tivy")
# Spatial analysis and mapping
vignette("spatial-analysis", package = "Tivy")
# Fish population analysis
vignette("fish-analysis", package = "Tivy")
peru_coastline
: Peruvian coastline coordinates for
spatial analysisperu_coast_parallels
: Parallel lines at different
nautical mile distancescalas_bitacora
: Sample haul datafaenas_bitacora
: Sample trip datatallas_bitacora
: Sample length dataContributions are welcome! Please consider:
If you use Tivy
in your research, please cite it as:
Ttito, H. (2025). Tivy: Tools for Fisheries Data Analysis in Peru.
R package version 0.1.1. https://github.com/HansTtito/Tivy
This project is licensed under the MIT License - see the LICENSE file for details.