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.
This exercise is part of the course
Analyzing Survey Data in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add conditional proportions to tab_DH
tab_DH_cond <- tab_DH %>%
as.data.frame() %>%
group_by(___) %>%
___(n_HealthGen = ___(Freq), Prop_Depressed = Freq/___) %>%
ungroup()