開始使用免費開始

來個 waffle 圖?

如果我們想更深入看一下「'other'」這個類別的細節呢?

我們來改用 waffle 圖,因為它更適合呈現多個類別。我們會沿用上一題的資料處理流程,不同的是這次保留所有疾病。

我們將使用函式庫 waffle,其中包含 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(___)
編輯並執行程式碼