4.8 Exercises
Draw the reactive graph for each app.
What happens if you flip
fct_infreq()
andfct_lump()
in the code that reduces the summary tables?
Answer
injuries %>%
mutate(diag = fct_infreq(fct_lump(diag)), n = 5) %>%
group_by(diag) %>%
summarise(n = as.integer(sum(weight)))
## # A tibble: 7 × 2
## diag n
## <fct> <int>
## 1 Other Or Not Stated 1806436
## 2 Fracture 1558961
## 3 Laceration 1432407
## 4 Strain, Sprain 1432556
## 5 Contusion Or Abrasion 1451987
## 6 Inter Organ Injury 988494
## 7 Other 940652
This order lumped the rarer conditions into “Other” and then did the sorting. However, since “Other” was the most frequent label, fct_infreq()
then put “Other” at the top, which is less desirable.
- Add an input control that lets the user decide how many rows to show in the summary tables.
Answer
refer to code in next section
- Provide a way to step through every narrative systematically with forward and backward buttons. Advanced: Make the list of narratives “circular” so that advancing forward from the last narrative takes you to the first.