開始使用免費開始

Tidy 大型表格

作為「tidyverse」與「bigmemory」套件組合運用的最後一個練習,你將再次使用 tidyrggplot2 套件,繪製 Borrower Income ratio 隨時間變化的圖表。

本練習屬於課程

R 的可擴展資料處理

檢視課程

練習說明

  • 載入 tidyrggplot2 套件。
  • 使用 pivot_longer() 函式將每年的計數彙整成長表。
  • 建立一個折線圖,x 軸為 Year、y 軸為 Count,並依 BIR 分色與分組。

動手互動練習

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

# Load the tidyr and ggplot2 packages
library(___)
library(___)

bir_df_wide %>% 
    # Transform the wide-formatted data.frame into the long format
    ___(-BIR, names_to = "Year", values_to = "Count") %>%
    # Use ggplot to create a line plot
    ggplot(aes(x = ___, y = ___, group = BIR, color = BIR)) + 
    ___
編輯並執行程式碼