1. 課題を見つける/仮説を立てる
2. 実験や観察をしてデータを集める
3. データを整理する
4. データを解析して仮説を検証する
- 整理されたデータを可視化する練習からはじめよう!
※資料作成は岩嵜航さん(東北大学)にご協力いただきました。
(左右キーで進みます!)
Return to HOME
https://www.autodeskresearch.com/publications/samestats/
library(tidyverse) #使う前にパッケージを読み込む head(diamonds, n = 5) #まずはdiamondsの中身を確認
## # A tibble: 5 × 10 ## carat cut color clarity depth table price x y z ## <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl> ## 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43 ## 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31 ## 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31 ## 4 0.29 Premium I VS2 62.4 58 334 4.2 4.23 2.63 ## 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75
gp = ggplot(data = diamonds) + #diamondsを使ったグラフをgpに格納
geom_histogram(aes(x = carat)) #グラフはヒストグラムでx軸はcarat
gp #gpを見せて
gp = ggplot(data = diamonds) + #diamondsを使ったグラフをgpに格納
geom_histogram(aes(x = price)) #グラフはヒストグラムでx軸はprice
gp #gpを見せて
gp = ggplot(data = diamonds) + #diamondsを使ったグラフをgpに格納
geom_histogram(aes(x = depth)) #グラフはヒストグラムでx軸はdepth
gp #gpを見せて
gp = ggplot(data = diamonds) + #diamondsを使ったグラフをgpに格納
geom_density(aes(x = price)) #グラフはヒストグラムでx軸は密度分布
gp #gpを見せて
gp = ggplot(data = AAA) +
geom_BBB(aes(x = XXX, y = YYY))
gp
gp2 = ggplot(data = diamonds) + #図をgp2に格納する
geom_point(aes(x = carat, y = price)) #散布図で、X軸はcarat、Y軸はprice
gp2 #gp2を見せて
gp2 = ggplot(data = diamonds) + #図をgp2に格納する
geom_point(aes(x = carat, y = price, color = cut))
#散布図で、X軸はcarat、Y軸はprice、色はcut
gp2 #gp2を見せて
head(diamonds) #まずはdiamondsの中身を確認
## # A tibble: 6 × 10 ## carat cut color clarity depth table price x y z ## <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl> ## 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43 ## 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31 ## 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31 ## 4 0.29 Premium I VS2 62.4 58 334 4.2 4.23 2.63 ## 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75 ## 6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48
gp2 = ggplot(data = diamonds) + #図をgp2に格納する
geom_point(aes(x = carat, y = price, color = carat))
#散布図で、X軸はcarat、Y軸はprice、色はcarat
gp2 #gp2を見せて
gp2 = ggplot(data = diamonds) + #図をgp2に格納する
geom_point(aes(x = carat, y = price, color = color))
#散布図で、X軸はcarat、Y軸はprice、色はcolor
gp2 #gp2を見せて
gp2 = ggplot(data = diamonds) + #図をgp2に格納する
geom_point(aes(x = carat, y = price, color = color)) +
facet_wrap(~ color) #colorごとにグラフを分ける
gp2 #gp2を見せて
gp2 = ggplot(data = diamonds) + #図をgp2に格納する
geom_point(aes(x = carat, y = price, color = color)) +
facet_grid(cut ~ color) #cutとcolorごとにグラフを分ける
gp2 #gp2を見せて
gp2 = ggplot(data = diamonds) + #図をgp2に格納する
geom_point(aes(x = carat, y = price, color = color)) +
facet_grid(. ~ color) #colorごとにグラフを分ける
gp2 #gp2を見せて
gp2 = ggplot(data = diamonds) + #図をgp2に格納する
geom_point(aes(x = carat, y = price, color = color)) +
facet_wrap( ~ cut) #cutごとにグラフを分ける
gp2 #gp2を見せて
gp2 = ggplot(data = diamonds) + #図をgp2に格納する
geom_point(aes(x = carat, y = price, color = color)) +
facet_grid(. ~ cut) #cutごとにグラフを分ける
gp2 #gp2を見せて
gp3 = ggplot(data = diamonds) + #図をgp3に格納する
geom_boxplot(aes(x = cut, y = carat, color = cut)) #xはcut, yはcarat
gp3 #gp2を見せて
gp3 = ggplot(data = diamonds) +
geom_boxplot(aes(x = cut, y = carat)) +
theme_classic() #テーマはクラシック
gp3
gp3 = ggplot(data = diamonds) +
geom_boxplot(aes(x = cut, y = carat), color = "red") + #線は赤
theme_classic()
gp3
gp3 = ggplot(data = diamonds) +
geom_boxplot(aes(x = cut, y = carat), fill = "red") + #箱は赤
theme_classic()
gp3
gp3 = ggplot(data = diamonds) +
geom_boxplot(aes(x = cut, y = carat, color = cut)) + #線の色はcut
theme_classic()
gp3
gp3 = ggplot(diamonds) +
geom_boxplot(aes(y = carat, x = cut, color = cut)) +
theme_classic() +
coord_cartesian(ylim = c(-1, 6)) +
#直角座標(Cartesian coordinates)のy軸は-1から6まで
labs(title = "Diamonds", x = "Size (carat)", y = "Price (USD)")
#タイトルや軸のラベル(labs)を設定
gp3
gp3 = ggplot(diamonds) +
geom_boxplot(aes(y = carat, x = cut)) +
theme_classic() +
theme(axis.title.x = element_text(size = 20), #X軸のタイトル
axis.title.y = element_text(size = 20), #Y軸のタイトル
axis.text.x = element_text(size = 15, angle = 30, hjust = 1),
#X軸の文字
axis.text.y = element_text(size = 15)) #Y軸の文字
gp3
ggsave("fig1.png", gp3, width = 4, height = 3, dpi = 300)