單變數分佈

R 的探索式資料分析

Andrew Bray

Assistant Professor, Reed College

邊際 vs. 條件

ggplot(cars, aes(x = hwy_mpg)) +
  geom_histogram()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Warning message:
Removed 14 rows containing non-finite values (stat_bin). 

第 2 章圖 2.003

R 的探索式資料分析

邊際 vs. 條件

ggplot(cars, aes(x = hwy_mpg)) +
  geom_histogram() +
  facet_wrap(~pickup)
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Warning message:
Removed 14 rows containing non-finite values (stat_bin).

第 2 章圖 2.006

R 的探索式資料分析

建立資料管線

cars2 <- cars %>%
  filter(eng_size < 2.0)

ggplot(cars2, aes(x = hwy_mpg)) +
  geom_histogram()
R 的探索式資料分析

建立資料管線

cars %>%
  filter(eng_size < 2.0) %>%
  ggplot(aes(x = hwy_mpg)) +
  geom_histogram()
R 的探索式資料分析

篩選與分面長條圖

cars %>%
  filter(eng_size < 2.0) %>%
  ggplot(aes(x = hwy_mpg)) +
  geom_histogram()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

第 2 章圖 2.011

R 的探索式資料分析

較寬箱寬

cars %>%
  filter(eng_size < 2.0) %>%
  ggplot(aes(x = hwy_mpg)) +
  geom_histogram(binwidth = 5)

第 2 章圖 2.013

R 的探索式資料分析

密度圖

cars %>%
  filter(eng_size < 2.0) %>%
  ggplot(aes(x = hwy_mpg)) +
  geom_density()

第 2 章圖 2.015

R 的探索式資料分析

較寬頻寬

cars %>%   
  filter(eng_size < 2.0) %>%
  ggplot(aes(x = hwy_mpg)) +
  geom_density(bw = 5)

第 2 章圖 2.017

R 的探索式資料分析

一起來練習吧!

R 的探索式資料分析

Preparing Video For Download...