盒鬚圖
盒鬚圖能呈現資料集的形狀、變異程度,以及中心(或中位數)。它特別適合用來顯示偏態的資料。
將資料集與標準常態分配比較時,你可以辨識與常態的偏離(不對稱、偏態等)。從盒子向外延伸的線稱為鬚,用來表示超出上、下四分位數之外的變異,也就是離群值。這些離群值通常會以與鬚對齊的單獨圓點標示。
在影片中,你也看到如何使用 boxplot() 建立水平的盒鬚圖:
> boxplot(amazon_stocks,
horizontal = TRUE,
main = "Amazon return distribution")
在這個練習中,你要為工作空間中的 rtn(Apple 的報酬率)繪製盒鬚圖。
本練習屬於課程
在 R 視覺化時間序列資料
練習說明
- 為
rtn的資料繪製盒鬚圖。 - 為 1000 個點的標準常態分配繪製盒鬚圖,你可以用
rnorm(1000)產生資料。 - 在同一個 2x1 的圖形視窗中,依原本順序,將兩個圖都重新繪製為水平圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Draw box and whisker plot for the Apple returns
# Draw a box and whisker plot of a normal distribution
# Redraw both plots on the same graphical window