Téléchargement des données : donnees.zip
Téléchargement de la présentation en pdf : Art_plast.pdf
A décompresser dans votre répertoire de travail
23/02/2021
Téléchargement des données : donnees.zip
Téléchargement de la présentation en pdf : Art_plast.pdf
A décompresser dans votre répertoire de travail
gps.df<-read.csv2("points.csv") head(gps.df) %>% kable("html") %>% kable_styling(font_size = 14,full_width = F)%>% kable_minimal() %>% row_spec(0, font_size=9)
X.1 | X | code_village | code_engin | code_pecheur | date_heure | longitude | latitude | coup_peche | site_peche | etat_detaille | etat_agrege | idpos | no_trajet |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 1 | MTK | FMCy | 4 | 2019-06-10 06:27:13 | -13.42464 | 9.275370 | NA | NA | NA | NA | 2820034 | 1175 |
2 | 2 | MTK | FMCy | 4 | 2019-06-24 10:04:20 | -13.42368 | 9.277128 | NA | NA | NA | NA | 2823301 | 0 |
3 | 3 | MTK | FMD | 2 | 2019-07-20 09:06:13 | -13.42375 | 9.277345 | NA | NA | NA | NA | 2831056 | 0 |
4 | 4 | MTK | FMCy | 4 | 2019-06-10 06:41:18 | -13.42761 | 9.279283 | NA | NA | NA | NA | 2820069 | 1175 |
5 | 5 | MTK | FMCy | 4 | 2019-06-10 06:41:34 | -13.42784 | 9.279324 | NA | NA | NA | NA | 2820070 | 1175 |
6 | 6 | MTK | FMCy | 4 | 2019-06-10 06:41:48 | -13.42812 | 9.279317 | NA | NA | NA | NA | 2820071 | 1175 |
Des points, le dataframe devient un objet sf —> st_as_sf
gps <- st_as_sf(gps.df, coords = c("longitude", "latitude"), crs = 4326) g1<-ggplot(gps) + geom_sf()
Des shapefiles : des données dans un contexte spatial
1 - world_borders.shp (et dbf associés)
world<-st_read('world_borders.shp',crs=4326)
## Reading layer `world_borders' from data source `/home2/jerome/BAS_jerome/39/world_borders.shp' using driver `ESRI Shapefile' ## Simple feature collection with 3784 features and 5 fields ## geometry type: POLYGON ## dimension: XY ## bbox: xmin: -180 ymin: -90 xmax: 180 ymax: 83.6236 ## CRS: EPSG:4326
world.gg<-ggplot(world) + geom_sf()
Cela permet de mettre ensemble des données spatiales décrites en degré depuis Bastia ou en mètre depuis Ajaccio
Le code CRS (n° de la projection) : https://epsg.org/search/by-name
head(as.data.frame(world)) %>% kable("html") %>% kable_styling(font_size = 14,full_width = F)%>% kable_minimal() %>% row_spec(0, font_size=9)
CAT | FIPS_CNTRY | CNTRY_NAME | AREA | POP_CNTRY | geometry |
---|---|---|---|---|---|
1 | AA | Aruba | 193 | 71218 | POLYGON ((-69.88223 12.4111… |
2 | AC | Antigua and Barbuda | 443 | 68320 | POLYGON ((-61.73889 17.5405… |
2 | AC | Antigua and Barbuda | 443 | 68320 | POLYGON ((-61.73806 16.9897… |
4 | AG | Algeria | 2381740 | 32129324 | POLYGON ((2.96361 36.80222,… |
5 | AJ | Azerbaijan | 86600 | 7868385 | POLYGON ((48.58395 41.83577… |
6 | AL | Albania | 28748 | 3544808 | POLYGON ((19.43621 41.02107… |
world %>% st_crop(xmin = -8, ymin = 47, xmax = 0, ymax = 52) %>% ggplot() + geom_sf()
world %>% ggplot() + geom_sf(aes(fill=POP_CNTRY)) ->world.gg2
grille<-st_read('grille.shp',crs=4326)
## Reading layer `grille' from data source `/home2/jerome/BAS_jerome/39/grille.shp' using driver `ESRI Shapefile' ## Simple feature collection with 10000 features and 1 field ## geometry type: POLYGON ## dimension: XY ## bbox: xmin: -18 ymin: 8 xmax: -13 ymax: 13 ## CRS: EPSG:4326
ggplot(grille) + geom_sf()
bb<-st_bbox(st_buffer(gps,0.2)) st_crop(world,xmin=bb$xmin[[1]],ymin=bb$ymin[[1]],xmax=bb$xmax[[1]],ymax=bb$ymax[[1]]) ->fond g2<-ggplot(gps) + geom_sf(color='red',cex=0.2)+geom_sf(data=fond) #ggplot(points) + geom_sf(color='red',cex=0.2)+geom_sf(data=fond)+facet_grid(~code_engin)
grille %>% st_join(gps,join = st_intersects,left=FALSE) %>% group_by(code_engin,id) %>% dplyr::summarize(npoints=n())->grille_points g3<-ggplot(grille_points)+ geom_sf(aes(fill=npoints),lwd = 0)+ geom_sf(data=gps,cex=0.1)+facet_grid(~code_engin)
Je veux des ronds proportionnels Mdame !! (st_centroid + parametre size)
grille_points %>% mutate(centre=st_centroid(geometry)) %>% ggplot()+geom_sf(aes(geometry=centre,size=npoints,col='red'))+ geom_sf(data=fond)+facet_grid(~code_engin)
grille_points %>% mutate(longi=st_coordinates(st_centroid(geometry))[,1],lati=st_coordinates(st_centroid(geometry))[,2]) %>% st_drop_geometry() %>% pivot_wider(names_from=code_engin,values_from=npoints) %>% replace_na(list(FMCy = 0,FMD=0)) %>% mutate(total=FMCy+FMD)->grille_cam grille_cam %>% kable("html") %>% kable_styling(font_size = 14,full_width = F) %>% kable_minimal()
id | longi | lati | FMCy | FMD | total |
---|---|---|---|---|---|
2489 | -13.575 | 9.225 | 3465 | 0 | 3465 |
2491 | -13.475 | 9.225 | 52 | 2078 | 2130 |
2492 | -13.425 | 9.225 | 1742 | 19 | 1761 |
2589 | -13.575 | 9.275 | 1181 | 0 | 1181 |
2591 | -13.475 | 9.275 | 2618 | 2867 | 5485 |
2592 | -13.425 | 9.275 | 841 | 1123 | 1964 |
2490 | -13.525 | 9.225 | 0 | 40 | 40 |
2590 | -13.525 | 9.275 | 0 | 793 | 793 |
2691 | -13.475 | 9.325 | 0 | 409 | 409 |
cam<-ggplot()+geom_sf(data=fond)+ geom_scatterpie(aes(x=longi,y=lati,group=id,r=total/200000),data=grille_cam,cols=c('FMCy','FMD'))+ geom_scatterpie_legend(grille_cam$total/200000, x=-13.5, y=9.1) cam
La liste des fonctions et packages
cam
library(leaflet) leaflet(grille_points) %>% addProviderTiles("CartoDB.Positron") %>% addPolygons(color = "black", fillColor = ~colorQuantile("YlOrRd", npoints)(npoints))
library(leaflet) leaflet(grille_cam) %>% addProviderTiles("CartoDB.Positron") %>% addCircles(lng = ~longi, lat = ~lati, weight = 1, radius = ~sqrt(total) * 30, popup = paste('Le nombre de position est ',grille_cam$total))
library(leaflet.extras2) library(geojsonsf) gps$date_heure2<-as.POSIXct(gps$date_heure) gps %>% filter(no_trajet==1175) -> gps.1175 leaflet(gps.1175) %>% addProviderTiles("CartoDB.Positron") %>% addCircleMarkers(radius = 0.1) %>% addTiles() %>%addTimeslider(data = gps.1175, options = timesliderOptions(position = "topright", timeAttribute = "date_heure2",range = TRUE,alwaysShowDate=TRUE)) %>% setView(-13.5, 9.3, 11)