加入一些抖動
我們可以在盒形圖後方加入抖動點,來改進前一個圖。把抖動點設定為好看的 'steelblue' 顏色,並將 alpha 設為 0.3,以便看出隨機重疊的情況。
另外,你也需要把盒形圖設為透明,這樣才能看見落在盒形圖「盒子」底下的點。
本練習屬於課程
R 視覺化最佳實務
練習說明
- 在盒形圖幾何層之前,先對圖物件加入
geom_jitter()。 - 將抖動點的顏色設為
'steelblue',並把alpha設為0.3。 - 將現有的盒形圖設為透明,方法是把
alpha設為 0。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
md_speeding %>%
filter(vehicle_color == 'RED') %>%
ggplot(aes(x = gender, y = speed)) +
# add jittered points with alpha of 0.3 and color 'steelblue'
___ +
# make boxplot transparent with alpha = 0
geom_boxplot(___) +
labs(title = 'Speed of red cars by gender of driver')