为不同用户类型构建图
让我们比较一下订阅了 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()