視覺化數值對類別
當解釋變數是類別型時,先前用來視覺化資料的散佈圖就不合適了。相對地,為每個類別各畫一張直方圖是個好選擇。
臺灣不動產資料集包含一個與屋齡相關的類別變數。屋齡被分成 3 組:0 到 15 年、15 到 30 年,以及 30 到 45 年。
taiwan_real_estate 已可使用,且已載入 ggplot2。
本練習屬於課程
R 迴歸入門
練習說明
- 使用
taiwan_real_estate,繪製price_twd_msq的直方圖,並設定10個 bins。 - 依
house_age_years分面,產生 3 個面板。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Using taiwan_real_estate, plot price_twd_msq
___ +
# Make it a histogram with 10 bins
___ +
# Facet the plot so each house age group gets its own panel
___