開始使用免費開始

為不同使用者類型建立圖形

來比較訂閱 divvy 單車的使用者,和較為隨性的未訂閱顧客之間的圖形吧。

在使用 graph_from_data_frame() 建立圖形前,先用 dplyr 處理資料會很方便。你會用到的一個實用 dplyr 函式是 n(),它會回傳該資料框分組中的列數。

本練習屬於課程

案例研究:R 的網路分析

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

subscribers <- bike_dat %>% 
  # Filter for rows where usertype is Subscriber
  ___(___ == "___")

# Count the number of subscriber trips
n_subscriber_trips <- nrow(___)

subscriber_trip_graph <- subscribers %>% 
  # Group by from_station_id and to_station_id
  ___(___, ___) %>% 
  # Calculate summary statistics
  summarize(
    # Set weights as proportion of total trips
    weights = ___() / n_subscriber_trips
  ) %>%
  # Make a graph from the data frame
  graph_from_dataframe()
編輯並執行程式碼