Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Case Studies: Network Analysis in R

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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()
Code bewerken en uitvoeren