Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
Running Code
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
Rows: 387593 Columns: 13
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
dbl (4): start_lat, start_lng, end_lat, end_lng
dttm (2): started_at, ended_at
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
You can add options to executable code like this
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(leaflet)
Warning: package 'leaflet' was built under R version 4.2.3
# Agrégation et filtrage des donnéesflux_data <- X202305_bluebikes_tripdata %>%group_by(start_station_id, end_station_id) %>%summarise(count =n(), .groups ='drop') %>%filter(count >100)# Préparation des données de localisationstart_locations <- X202305_bluebikes_tripdata %>%select(start_station_id, start_lat, start_lng) %>%distinct(start_station_id, .keep_all =TRUE) %>%rename(end_lat = start_lat, end_lng = start_lng) # Renommer les colonnes pour la jointureend_locations <- X202305_bluebikes_tripdata %>%select(end_station_id, start_lat, start_lng) %>%distinct(end_station_id, .keep_all =TRUE) %>%rename(start_lat = start_lat, start_lng = start_lng) # Renommer les colonnes pour la jointure# Joindre les donnéesflux_data <- flux_data %>%left_join(start_locations, by ="start_station_id") %>%left_join(end_locations, by ="end_station_id")# Vérifier si la relation plusieurs-à-plusieurs persiste# (Supprimez ces lignes après vérification)print(summarise(flux_data, n =n_distinct(start_station_id, end_station_id)))
# A tibble: 1 × 1
n
<int>
1 161
# Filtrer les lignes avec des coordonnées non initialisées ou inconnuesflux_data <- flux_data %>%filter(!is.na(start_lat) &!is.na(start_lng) &!is.na(end_lat) &!is.na(end_lng))# Créer la carte Leafletmap <-leaflet(flux_data) %>%addTiles()# Ajouter les lignes de fluxfor(i in1:nrow(flux_data)){ map <- map %>%addPolylines(lng =c(flux_data$start_lng[i], flux_data$end_lng[i]),lat =c(flux_data$start_lat[i], flux_data$end_lat[i]),color ='gray', weight =1 )}# Afficher la cartemap
# Agrégation et filtrage des donnéesflux_data <- X202305_bluebikes_tripdata %>%group_by(start_station_id, end_station_id) %>%summarise(count =n(), .groups ='drop') %>%filter(count >100)# Préparation des données de localisationstart_locations <- X202305_bluebikes_tripdata %>%select(start_station_id, start_lat, start_lng) %>%distinct(start_station_id, .keep_all =TRUE) %>%rename(end_lat = start_lat, end_lng = start_lng) # Renommer les colonnes pour la jointureend_locations <- X202305_bluebikes_tripdata %>%select(end_station_id, start_lat, start_lng) %>%distinct(end_station_id, .keep_all =TRUE) %>%rename(start_lat = start_lat, start_lng = start_lng) # Renommer les colonnes pour la jointure# Joindre les donnéesflux_data <- flux_data %>%left_join(start_locations, by ="start_station_id") %>%left_join(end_locations, by ="end_station_id")# Vérifier si la relation plusieurs-à-plusieurs persiste# (Supprimez ces lignes après vérification)print(summarise(flux_data, n =n_distinct(start_station_id, end_station_id)))
# A tibble: 1 × 1
n
<int>
1 161
# Filtrer les lignes avec des coordonnées non initialisées ou inconnuesflux_data <- flux_data %>%filter(!is.na(start_lat) &!is.na(start_lng) &!is.na(end_lat) &!is.na(end_lng))# Créer la carte Leafletmap <-leaflet(flux_data) %>%addTiles()# Ajouter les lignes de fluxfor(i in1:nrow(flux_data)){ map <- map %>%addPolylines(lng =c(flux_data$start_lng[i], flux_data$end_lng[i]),lat =c(flux_data$start_lat[i], flux_data$end_lat[i]),color ='gray', weight =1 )}# Afficher la cartemap
The echo: false option disables the printing of code (only output is displayed).