Project 1

Author

Ryan Juica

Introduction

This dataset tracks adult nutrition, physical activity, and weight status metrics derived from the CDC’s Behavioral Risk Factor Surveillance System (BRFSS). It provides national and state specific data broken down by demographic categories. It has 199k rows and 33 columns. 

It has 7 quantitative variables:

  • YearStart, YearEnd, Data_Value, Data_Value_Alt, Low_Confidence_Limit, High_Confidence_Limit, and Sample_Size.

and 9 qualitative variables:

  • LocationAbbr, LocationDesc, Class, Topic, Question, Data_Value_Unit, Data_Value_Type, StratificationCategory1, and Stratification1

Source:

Centers for Disease Control and Prevention (CDC), National Center for Chronic Disease Prevention and Health Promotion, Division of Nutrition, Physical Activity, and Obesity. (https://data.cdc.gov/Nutrition-Physical-Activity-and-Obesity/Nutrition-Physical-Activity-and-Obesity-Behavioral/hn4x-zwk7/about_data)

Setting up libraries

library(tidyverse)
Warning: package 'dplyr' was built under R version 4.5.3
Warning: package 'lubridate' was built under R version 4.5.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(dplyr)

Setting up working directories

setwd('C:/Users/ryanj/Downloads/110 DATA')
health_df <- read_csv('Nutrition,_Physical_Activity,_and_Obesity_-_Behavioral_Risk_Factor_Surveillance_System_20261013.csv')
Rows: 118580 Columns: 33
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (26): LocationAbbr, LocationDesc, Datasource, Class, Topic, Question, Da...
dbl  (6): YearStart, YearEnd, Data_Value, Data_Value_Alt, Low_Confidence_Lim...
num  (1): Sample_Size

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Looking into the data

head(health_df)
# A tibble: 6 × 33
  YearStart YearEnd LocationAbbr LocationDesc Datasource    Class Topic Question
      <dbl>   <dbl> <chr>        <chr>        <chr>         <chr> <chr> <chr>   
1      2011    2011 AL           Alabama      Behavioral R… Obes… Obes… Percent…
2      2011    2011 AL           Alabama      Behavioral R… Obes… Obes… Percent…
3      2011    2011 AL           Alabama      Behavioral R… Obes… Obes… Percent…
4      2011    2011 AL           Alabama      Behavioral R… Obes… Obes… Percent…
5      2011    2011 AL           Alabama      Behavioral R… Obes… Obes… Percent…
6      2011    2011 AL           Alabama      Behavioral R… Obes… Obes… Percent…
# ℹ 25 more variables: Data_Value_Unit <chr>, Data_Value_Type <chr>,
#   Data_Value <dbl>, Data_Value_Alt <dbl>, Data_Value_Footnote_Symbol <chr>,
#   Data_Value_Footnote <chr>, Low_Confidence_Limit <dbl>,
#   High_Confidence_Limit <dbl>, Sample_Size <dbl>, Total <chr>,
#   `Age(years)` <chr>, Education <chr>, Sex <chr>, Income <chr>,
#   `Race/Ethnicity` <chr>, GeoLocation <chr>, ClassID <chr>, TopicID <chr>,
#   QuestionID <chr>, DataValueTypeID <chr>, LocationID <chr>, …
names(health_df)
 [1] "YearStart"                  "YearEnd"                   
 [3] "LocationAbbr"               "LocationDesc"              
 [5] "Datasource"                 "Class"                     
 [7] "Topic"                      "Question"                  
 [9] "Data_Value_Unit"            "Data_Value_Type"           
[11] "Data_Value"                 "Data_Value_Alt"            
[13] "Data_Value_Footnote_Symbol" "Data_Value_Footnote"       
[15] "Low_Confidence_Limit"       "High_Confidence_Limit"     
[17] "Sample_Size"                "Total"                     
[19] "Age(years)"                 "Education"                 
[21] "Sex"                        "Income"                    
[23] "Race/Ethnicity"             "GeoLocation"               
[25] "ClassID"                    "TopicID"                   
[27] "QuestionID"                 "DataValueTypeID"           
[29] "LocationID"                 "StratificationCategory1"   
[31] "Stratification1"            "StratificationCategoryId1" 
[33] "StratificationID1"         
#Looking at specfic varibles to answer 1st Visualization question
unique(health_df$Question)
[1] "Percent of adults aged 18 years and older who have obesity"                                                                                                                                                                                                                          
[2] "Percent of adults aged 18 years and older who have an overweight classification"                                                                                                                                                                                                     
[3] "Percent of adults who achieve at least 150 minutes a week of moderate-intensity aerobic physical activity or 75 minutes a week of vigorous-intensity aerobic activity (or an equivalent combination)"                                                                                
[4] "Percent of adults who achieve at least 150 minutes a week of moderate-intensity aerobic physical activity or 75 minutes a week of vigorous-intensity aerobic physical activity (or an equivalent combination) and engage in muscle-strengthening activities on 2 or more days a week"
[5] "Percent of adults who achieve more than 300 minutes a week of moderate-intensity aerobic physical activity or 150 minutes a week of vigorous-intensity aerobic activity (or an equivalent combination)"                                                                              
[6] "Percent of adults who engage in muscle-strengthening activities on 2 or more days a week"                                                                                                                                                                                            
[7] "Percent of adults who engage in no leisure-time physical activity"                                                                                                                                                                                                                   
[8] "Percent of adults who report consuming fruit less than one time daily"                                                                                                                                                                                                               
[9] "Percent of adults who report consuming vegetables less than one time daily"                                                                                                                                                                                                          
#Checking specfic naming to use in visulations
unique(health_df$StratificationCategory1)
[1] "Income"         "Age (years)"    "Race/Ethnicity" "Education"     
[5] "Sex"            "Total"         

Checking for NA values in Data_Value

colSums(is.na(health_df))
                 YearStart                    YearEnd 
                         0                          0 
              LocationAbbr               LocationDesc 
                         0                          0 
                Datasource                      Class 
                         0                          0 
                     Topic                   Question 
                         0                          0 
           Data_Value_Unit            Data_Value_Type 
                    106260                          0 
                Data_Value             Data_Value_Alt 
                     14461                      14461 
Data_Value_Footnote_Symbol        Data_Value_Footnote 
                    104119                     104119 
      Low_Confidence_Limit      High_Confidence_Limit 
                     14461                      14461 
               Sample_Size                      Total 
                     14461                     114345 
                Age(years)                  Education 
                     93170                     101640 
                       Sex                     Income 
                    110110                      88935 
            Race/Ethnicity                GeoLocation 
                     84700                       2156 
                   ClassID                    TopicID 
                         0                          0 
                QuestionID            DataValueTypeID 
                         0                          0 
                LocationID    StratificationCategory1 
                         0                          0 
           Stratification1  StratificationCategoryId1 
                         0                          0 
         StratificationID1 
                         0 

Does Income levels affect obesity?

Filter data to obesity and income and order the income

obesity_income <- health_df |>
  filter(Question == 'Percent of adults aged 18 years and older who have obesity' &
           StratificationCategory1 == 'Income' & Stratification1 != 'Data not reported' & !is.na(Data_Value)) |>
  arrange(desc(Data_Value))
head(obesity_income)
# A tibble: 6 × 33
  YearStart YearEnd LocationAbbr LocationDesc   Datasource  Class Topic Question
      <dbl>   <dbl> <chr>        <chr>          <chr>       <chr> <chr> <chr>   
1      2024    2024 GU           Guam           Behavioral… Obes… Obes… Percent…
2      2022    2022 VI           Virgin Islands Behavioral… Obes… Obes… Percent…
3      2021    2021 VI           Virgin Islands Behavioral… Obes… Obes… Percent…
4      2024    2024 MS           Mississippi    Behavioral… Obes… Obes… Percent…
5      2024    2024 VI           Virgin Islands Behavioral… Obes… Obes… Percent…
6      2024    2024 GU           Guam           Behavioral… Obes… Obes… Percent…
# ℹ 25 more variables: Data_Value_Unit <chr>, Data_Value_Type <chr>,
#   Data_Value <dbl>, Data_Value_Alt <dbl>, Data_Value_Footnote_Symbol <chr>,
#   Data_Value_Footnote <chr>, Low_Confidence_Limit <dbl>,
#   High_Confidence_Limit <dbl>, Sample_Size <dbl>, Total <chr>,
#   `Age(years)` <chr>, Education <chr>, Sex <chr>, Income <chr>,
#   `Race/Ethnicity` <chr>, GeoLocation <chr>, ClassID <chr>, TopicID <chr>,
#   QuestionID <chr>, DataValueTypeID <chr>, LocationID <chr>, …

Creating the barplot

ggplot(obesity_income, aes(x = Stratification1, y = Data_Value, fill = Stratification1)) +
  geom_bar(position = 'dodge', stat = 'identity') +
  scale_fill_manual(values = c('#318040', '#e76f51', '#666370', '#2b5c8f', '#D33E43', '#e9c46a')) +
  theme_light() +
  labs(
    title = 'Adult Obesity by Income Level',
    x = 'Income Level',
    y = 'Percentage of Adults (%)',
    fill = 'Income Level',
    caption = 'Source: Centers for Disease Control and Prevention (CDC)'
  ) +
  theme(
    axis.text.x = element_text(angle = 20, hjust = 1) 
  ) + 
  scale_x_discrete(labels = function(x) str_wrap(x, width = 5))# Cleans up x-axis label overlap

Does education level affect obesity rates?

Filtering obesity and education

# Filter data for education and obesity
box_data <- health_df %>%
  filter(Question == 'Percent of adults aged 18 years and older who have obesity',
         StratificationCategory1 == 'Education' & !is.na(Data_Value))

Creating the boxplot

ggplot(box_data, aes(x = Stratification1, y = Data_Value, fill = Stratification1)) +
  geom_boxplot() +
  scale_fill_manual(values = c('#3A7EC5', '#C5813A', '#92A45B', '#6D5BA4')) +
  theme_grey() +
  labs(
    title = 'Adult Obesity Rates by Education Level',
    x = 'Education Level',
    y = 'Obesity Prevalence (%)',
    fill = 'Education Level',
    caption = 'Source: Centers for Disease Control and Prevention (CDC)'
  ) +
  theme(
    axis.text.x = element_text(angle = 15, hjust = 1)
  ) +
  scale_x_discrete(labels = function(x) str_wrap(x, width = 5))