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.
Diese Übung ist Teil des Kurses
Analyzing Survey Data in R
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Add conditional proportions to tab_DH
tab_DH_cond <- tab_DH %>%
as.data.frame() %>%
group_by(___) %>%
___(n_HealthGen = ___(Freq), Prop_Depressed = Freq/___) %>%
ungroup()