Maritime Pirate Attacks

Author

François Pelletier

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.5.1
✔ ggplot2   4.0.1     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.2
✔ purrr     1.0.4     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
library(sf)
Linking to GEOS 3.14.1, GDAL 3.12.3, PROJ 9.8.1; sf_use_s2() is TRUE
library(leaflet)
# library(dataReporter) -- not available in this environment
source("importer_donnees_csv.R")
source("pirateIcon.R")
glimpse(pirate_attacks_sf, width = 67)
Rows: 7,511
Columns: 15
$ date                 <date> 1993-01-02, 1993-01-04, 1993-01-06,…
$ time                 <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, …
$ attack_type          <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, …
$ location_description <chr> "Hong Kong - Luzon - Hainan", "Hong …
$ nearest_country      <chr> "CHN", "CHN", "CHN", "CHN", "PHL", "…
$ eez_country          <chr> "TWN", "CHN", "TWN", "CHN", "PHL", "…
$ shore_distance       <dbl> 357.5023726, 47.4315725, 280.8118709…
$ shore_longitude      <dbl> 115.825956, 115.825956, 114.302501, …
$ shore_latitude       <dbl> 22.746644, 22.746644, 22.044867, 29.…
$ attack_description   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, …
$ vessel_name          <chr> "Mv Cosmic Leader", "Mv Tricolor Sta…
$ vessel_type          <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, …
$ vessel_status        <chr> NA, NA, NA, NA, NA, NA, NA, NA, "Anc…
$ data_source          <chr> "mappingpiracy", "mappingpiracy", "m…
$ geometry             <POINT> POINT (116.9667 19.7), POINT (116 …
pirate_attacks_sf_ss <- pirate_attacks_sf %>%
  filter(data_source == "imb") %>%
select(
  date,
  attack_type,
  shore_distance,
  vessel_type,
  vessel_status
) %>%
  replace_na(list(vessel_status="Underway")) %>%
  mutate(month_event = month(date),
         year_event = year(date))

Statistiques descriptives

# makeDataReport(pirate_attacks_sf_ss, replace = TRUE) -- dataReporter not available

Exporter les types de navires

pirate_attacks_sf_ss %>%
  group_by(vessel_type) %>%
  st_set_geometry(NULL) %>%
  count() %>%
  arrange(desc(n)) %>%
  write_csv("vessel_types.csv")

Traitement manuel

Je crée manuellement des catégories plus larges, puis je réimporte

custom_vessel_categories <-
  read_csv(
    "data/csv/custom_vessel_categories.csv",
    col_types = cols(vessel_type = col_character(),
                     vessel_category = col_character())
  )
pirate_attacks_sf_ss2 <- pirate_attacks_sf_ss %>% 
  left_join(custom_vessel_categories)
Joining with `by = join_by(vessel_type)`
pirate_attacks_sf_ss2 %>% sf::write_sf("data/geojson/pirate_attacks_sf_ss2.geojson")
writing: substituting ENGCRS["Undefined Cartesian SRS with unknown unit"] for missing CRS
Warning in CPL_write_ogr(obj, dsn, layer, driver,
as.character(dataset_options), : GDAL Error 6: DeleteLayer() not supported by
this dataset.

Filtrage

pirate_attacks_sf_maps <- pirate_attacks_sf_ss2 %>%
  filter(year_event == 2015, month_event==1)
m <- leaflet(pirate_attacks_sf_maps) %>%
  addTiles() %>%
  addMarkers(
    popup = paste0(
      "Type: ",
      pirate_attacks_sf_maps$vessel_category,
      "<br>",
      "Statut: ",
      pirate_attacks_sf_maps$vessel_status,
      "<br>",
      "Type d'attaque: ",
      pirate_attacks_sf_maps$attack_type,
      "<br>",
      "Distance de la côte: ",
      round(pirate_attacks_sf_maps$shore_distance, 2),
      "km",
      "<br>",
      "Date: ",
      pirate_attacks_sf_maps$date
    ),
    icon = pirateIcon,
    clusterOptions = markerClusterOptions()
  )