拿R來畫畫(四):毫無技巧的箱線圖

繪製箱線圖

  • 觀察數據
head(ToothGrowth)
A data.frame: 6 × 3
lensuppdose
<dbl><fct><dbl>
4.2VC0.5
11.5VC0.5
7.3VC0.5
5.8VC0.5
6.4VC0.5
10.0VC0.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()

在這裏插入圖片描述

發佈了135 篇原創文章 · 獲贊 56 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章