1. Learn
  2. /
  3. Courses
  4. /
  5. Analyzing Survey Data in R

Exercise

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.

Instructions 1/3

undefined XP
    1
    2
    3
  • Add two columns to the data frame, tab_DH: a column, called n_HealthGen, of the estimated count in each category of HealthGen and a column, called Prop_Depressed which contains the depression rates for each category of HealthGen.