데이터 보강: 경로 요약 통계
시각화를 거의 준비한 route_hod 데이터셋을 만들었어요. 이제 대화형 디스플레이를 볼 때 유용한 코그노스틱스로 활용할 몇 가지 변수를 더 추가해 보겠습니다.
이 연습은 강의의 일부입니다
R에서 Trelliscope로 빅데이터 시각화하기
연습 안내
- 각 경로별로 총 승차 횟수를 계산하세요.
- 각 경로별로 평일 근무일(work week) 동안의 시간당 평균 승차 수와 주말의 시간당 평균 승차 수의 차이를 계산하세요. 변수
n은 이미 시간당 집계된 건수이므로, 예를 들어 평일 평균은mean(n[weekday == "workweek"])로 계산합니다. - 각 경로별로 Google Maps에서 해당 경로를 가리키는 URL을 담은 변수를 추가하세요. 제공된
make_gmap_url함수를 사용하고, 데이터에서 적절한 인수를 전달하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
library(trelliscopejs)
library(ggplot2)
library(dplyr)
# Function to construct a Google maps URL with cycling directions
make_gmap_url <- function(start_lat, start_lon, end_lat, end_lon) {
paste0("https://www.google.com/maps/dir/?api=1",
"&origin=", start_lat, ",", start_lon,
"&destination=", end_lat, ",", end_lon,
"&travelmode=bicycling")
}
# Compute tot_rides, weekday_diff, and map_url
route_hod_updated <- route_hod %>% ungroup() %>%
group_by(start_station_code, end_station_code) %>%
mutate(
tot_rides = sum(___),
weekday_diff = mean(n[weekday == "workweek"]) - ___,
map_url = ___)