总结

R 中的探索性数据分析

Andrew Bray

Assistant Professor, Reed College

饼图 vs. 条形图

饼图 vs. 条形图

R 中的探索性数据分析

分面 vs. 叠加

分面 vs. 叠加

R 中的探索性数据分析

直方图

ggplot(data, aes(x = var1)) +
    geom_histogram()

ch4_4.004.png

R 中的探索性数据分析

核密度图

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

ch4_4.005.png

R 中的探索性数据分析

并列箱线图

ggplot(common_cyl, aes(x = as.factor(ncyl), y = city_mpg)) +
  geom_boxplot()
Warning message:
Removed 11 rows containing non-finite values (stat_boxplot).

ch4_4.006.png

R 中的探索性数据分析

中心:均值、中位数、众数

x
76 78 75 74 76 72 74 73 73 75 74
table(x)
x
72 73 74 75 76 78 
 1  2  3  2  2  1

ch4_4.007.png

R 中的探索性数据分析

收入的分布形状

ggplot(life, aes(x = income, fill = west_coast)) +
  geom_density(alpha = .3)
ggplot(life, aes(x = log(income), fill = west_coast)) +
  geom_density(alpha = .3)

ch4_4.008.png

R 中的探索性数据分析

使用 group_by()

life %>%
  slice(240:247) %>%
  group_by(west_coast) %>%
  summarize(mean(expectancy))
# A tibble: 2 x 2
  west_coast mean(expectancy)
       <lgl           <dbl>
1      FALSE         79.26125
2       TRUE         79.29375

ch4_4.009.png

R 中的探索性数据分析

垃圾邮件与感叹号

email %>%
  mutate(zero = exclaim_mess == 0) %>%
  ggplot(aes(x = zero, fill = spam)) +
  geom_bar()

ch4_4.010.png

R 中的探索性数据分析

垃圾邮件与图片

email %>%
  mutate(has_image = image 0) %>%
  ggplot(aes(x = as.factor(has_image), fill = spam)) +
  geom_bar(position = "fill")

ch4_4.011.png

R 中的探索性数据分析

¡Vamos a practicar!

R 中的探索性数据分析

Preparing Video For Download...