開始使用免費開始

加上權重的最常往返站點

到目前為止,我們只用無權重的邊來看網路。不過,我們的邊權重其實代表行程次數,因此把度數分析擴充為加權度數分佈是合理的。這很重要,因為即使度數比例平衡,真正需要重新平衡的其實是腳踏車。如果所有站點的權重都一樣,無權重的度數比例就足夠;但若想知道實際流動了多少腳踏車,就必須把權重納入考量。

度數分佈的加權對應指標是「strength」。你可以用 strength() 函式計算,它會根據圖中邊的 weight 屬性,產生加權的度數分佈。

本練習屬於課程

案例研究:R 的網路分析

檢視課程

練習說明

  • 建立一個資料框,包含以下欄位:
    • trip_out:放入 trip_g_simp 的加權度數(strength)分佈,方向為 "out"
    • trip_in:放入方向為 "in" 的加權度數分佈。
    • ratio:放入「out」度數除以「in」度數的比值。
  • 篩選 trip_strng,只保留 trip_outtrip_in 都大於 10 的列。
  • 繪製上述篩選後之 ratio 的直方圖。

動手互動練習

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

trip_strng <- data_frame(
  # Find the "out" strength distribution
  trip_out = strength(___, mode = "___"), 
  # ... and the "in" strength distribution
  trip_in = strength(___, mode = "in"),
  # Calculate the ratio of out / in
  ratio = ___ / trip_in
)

trip_strng_filtered <- trip_strng %>%
  # Filter for rows where trips in and out are both over 10
  filter(___ > 10, ___ > 10) 

# Plot histogram of filtered ratios
hist(___$ratio)
編輯並執行程式碼