繪製箱線圖
- 觀察數據
head(ToothGrowth)
len | supp | dose |
---|---|---|
<dbl> | <fct> | <dbl> |
4.2 | VC | 0.5 |
11.5 | VC | 0.5 |
7.3 | VC | 0.5 |
5.8 | VC | 0.5 |
6.4 | VC | 0.5 |
10.0 | VC | 0.5 |
- 基礎箱線圖:傳入因子型變量x和數值變量y
boxplot(len~supp, data = ToothGrowth)
- 更爲細分變量
boxplot(len~supp+dose, data = ToothGrowth)
- ggplot版本
library(ggplot2)
ggplot(ToothGrowth, aes(x=supp, y = len)) + geom_boxplot()
ggplot(ToothGrowth, aes(x=interaction(supp, dose), y = len)) + geom_boxplot()