LoginSignup
3
0

More than 1 year has passed since last update.

【R】箱ひげ図を描く方法

Last updated at Posted at 2019-02-03

箱ひげ図は、複数のグループ間でデータの分布を図示して比較する方法です。
ごく基本的な作図で、t検定や分散分析(ANOVA)の結果と併せて用いられることが多いと思います。

解析に使うデータ

  • 以下のデータは、ある山の東側(east)と西側(west)で測定した葉のサイズ(mm^2)です。
leaf_size.csv
east,west
4632.4,4159.1
3481,3844.4
3267.8,3135.0
3130.9,2837.2
3108,2801.2
2575.4,2587.8
4556.9,5180.1
4343.5,3635.9
4130.3,2651.1
2824,2642.7

箱ひげ図の描画

最も単純な箱ひげ図の描画

  • 上記の"leaf_size.csv"をデータフレームとして読み込んだ場合、このデータフレームを"boxplot"関数の引数として指定するだけで箱ひげ図を描画できます。
Rのコンソール
> # leaf_size.csvを読み込んで、"leaf_size"という名前のデータフレームに格納する。
> leaf_size <- read.table("C:\\leaf_size.csv", header=TRUE, encoding="CP932", sep=",")
> # 箱ひげ図の描画
> boxplot(leaf_size)

boxplot_01.png

軸のラベルとタイトルを指定した箱ひげ図の描画

  • X軸のラベルは"xlab"パラメーター、Y軸のラベルは"ylab"パラメーターで指定できます。
  • グラフのタイトルは"main"パラメーターで指定できます。
Rのコンソール
> # Y軸のラベルとタイトルを指定した箱ひげ図の描画
> boxplot(leaf_size, ylab="leaf size(mm^2)", main="Leaf size in Mt.Miyatsuka")

boxplot_03.png

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0