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.
Bu egzersiz
Analyzing Survey Data in R
kursunun bir parçasıdırUygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Add conditional proportions to tab_DH
tab_DH_cond <- tab_DH %>%
as.data.frame() %>%
group_by(___) %>%
___(n_HealthGen = ___(Freq), Prop_Depressed = Freq/___) %>%
ungroup()