开始使用免费开始使用

来块华夫图?

如果我们对 'other' 类别的细节感兴趣,该怎么办?

让我们改用华夫图(waffle chart),因为它能处理更多类别。我们将沿用上一个练习的数据处理管道,不过这次保留所有疾病类别。

我们将使用库 waffle,其中包含函数 waffle()。当您提供一个带名称的计数向量时,该函数会为您生成华夫图。

它会为向量中提供的每个单位绘制一个小方块,所以我们需要把疾病计数转换为四舍五入的百分比(请注意已提供的数据整理代码中的 mutate() 调用)。

本练习是课程的一部分

R 中的可视化最佳实践

查看课程

练习说明

  • 使用 names() 函数为向量 case_counts 添加名称。
  • 调用库 waffle 中的 waffle() 函数,并将向量 case_counts 作为参数传入。

交互式实操练习

通过完成这段示例代码来试试这个练习。

disease_counts <- who_disease %>%
group_by(disease) %>%
	summarise(total_cases = sum(cases)) %>% 
	mutate(percent = round(total_cases/sum(total_cases)*100))

# Create an array of rounded percentages for diseases.
case_counts <- disease_counts$percent
# Name the percentage array with disease_counts$disease
___

# Pass case_counts vector to the waffle function to plot
waffle(___)
编辑并运行代码