ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Analyzing Survey Data in R

Ver curso

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# Add conditional proportions to tab_DH
tab_DH_cond <- tab_DH %>%
    as.data.frame() %>%
    group_by(___) %>%
    ___(n_HealthGen = ___(Freq), Prop_Depressed = Freq/___) %>%
    ungroup()
Editar y ejecutar código