饼图及其近亲

R 中的可视化最佳实践

Nick Strayer

Instructor

什么是比例?

  • 构成整体的部分
  • 常用于人口分析

R 中的可视化最佳实践

饼图

  • 往往是人们最先学的图表
  • 也是人们最先开始不喜欢的图表
  • 这种不喜欢并非完全合理

R 中的可视化最佳实践

不太"香"的饼

  • 饼图不够精确
    • 用角度编码数据
  • 不适合类别很多的情况
    • 超过三块后难以比较

R 中的可视化最佳实践

好看的饼

  • 直观且紧凑
who_disease %>% 
  mutate(
    region = ifelse(
      region %in% c('EUR', 'AFR'), 
      region, 'Other')
  ) %>% 
  ggplot(aes(x = 1, fill = region)) +
    geom_bar(color = 'white') +
    coord_polar(theta = "y") +
    theme_void()

R 中的可视化最佳实践

华夫图

  • 比饼图更精确
  • 用面积而非角度编码数据
obs_by_region <- who_disease %>%
  group_by(region) %>% summarise(num_obs = n()) %>% 
  mutate(percent = round(num_obs/sum(num_obs)*100))

# Array of rounded percentages
percent_by_region <- obs_by_region$percent
names(percent_by_region) <- obs_by_region$region

# Send array of percentages to waffle plot function
waffle::waffle(percent_by_region, rows = 5)
R 中的可视化最佳实践

华夫图

R 中的可视化最佳实践

让我们来练习!

R 中的可视化最佳实践

Preparing Video For Download...