library(tidyverse)
library(lubridate)
library(sf)
library(leaflet)
library(dataReporter)
source("importer_donnees_csv.R")
Avis : One or more parsing issues, see `problems()` for details
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))
makeDataReport(pirate_attacks_sf_ss, replace = TRUE)
Data report generation is finished. Please wait while your output file is being rendered.
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, by = "vessel_type"
pirate_attacks_sf_ss2 %>% sf::write_sf("data/geojson/pirate_attacks_sf_ss2.geojson")
Avis dans CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options), :
GDAL Error 6: DeleteLayer() not supported by this dataset.
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()
)
m