Making Graphs of Different User Types
Let's compare graphs of people who subscribe to the divvy bike vs. more casual non-subscribing customers.
It's convenient to use dplyr
to manipulate the data before using graph_from_data_frame()
to create the graph. One useful dplyr
function you'll need is n()
, which gives the number of rows in that group of the data frame.
This exercise is part of the course
Case Studies: Network Analysis in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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()