Building segments bar graphs
"What is the probability that a person in excellent health suffers from depression?" and "Are depression rates lower for healthier people?" are questions we can start to answer by adding conditional proportions to tab_DH
and creating a segmented bar graph.
Notice that we need to use ungroup()
in our data wrangling below.
Cet exercice fait partie du cours
Analyzing Survey Data in R
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Add conditional proportions to tab_DH
tab_DH_cond <- tab_DH %>%
as.data.frame() %>%
group_by(___) %>%
___(n_HealthGen = ___(Freq), Prop_Depressed = Freq/___) %>%
ungroup()