How about a waffle?
What if we are interested in the details of the 'other' class?
Let's make the switch to a waffle chart, as they are capable of dealing with more classes. We'll use the same data-manipulation pipeline from the last exercise, but this time with all the diseases left in.
We will use the library waffle which contains the function waffle(). This function produces a waffle chart for you when supplied with a named vector of counts.
It will draw one square for each unit supplied in the vector, so we need to manipulate our disease counts to rounded percents (note the mutate() call in the supplied data wrangling code).
Este exercício faz parte do curso
Visualization Best Practices in R
Instruções do exercício
- Give the
case_countsvector names using thenames()function. - Call the
waffle()function in the librarywafflewith thecase_countsvector supplied as an argument.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
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(___)