---
title: ""
author: ""
output:
flexdashboard::flex_dashboard:
theme: default
horizontal_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(dygraphs)
library(highcharter)
library(tidyverse)
library(lubridate)
library(forcats)
library(zoo)
library(xts)
library(readxl)
library(forecast)
options(scipen = 999)
```
Global Obesity Prevalence {data-navmenu="Obesity Prevalence"}
=====================================
row {.tabset data-width=1000}
-----------------------------------------------------------------------
### Annual Obesity Prevalence: World View
```{r data-prep-obj1, include=FALSE}
## Reading the dataset
obj1_data <- read_csv("Obesity/Obesity/prevalence-of-obesity-in-adults-by-region.csv")
## Selecting the world prevalence from the obesity prevalence dataframe
world_obesity_prevalence <- obj1_data %>%
filter(Entity == "World") %>%
rename(Prevalence = `Prevalence of obesity in adults (18+ years old) (FAO (2017)) (%)`) %>%
select(Year, Entity, Prevalence)
## Selecting the regional prevalence from the obesity prevalence dataframe
regional_obesity_prevalence <- obj1_data %>%
filter(!Entity == "World") %>%
rename(Prevalence = `Prevalence of obesity in adults (18+ years old) (FAO (2017)) (%)`) %>%
select(Year, Entity, Prevalence) %>%
spread(Entity, Prevalence)
```
```{r}
## generating a time series object
world_obesity_prevalence_ts <- ts(world_obesity_prevalence[,-c(1, 2)], start = 1975, frequency = 1)
## Charting the world obesity prevalence
hchart(world_obesity_prevalence_ts, name = "Annual Obesity Prevalence") %>%
hc_xAxis(title = list(text = "Date")) %>%
hc_yAxis(title = list(text = "Obesity Prevalence (%)")) %>%
hc_title(text = "World Obesity Prevalence (%)")
```
### Annual Obesity Prevalence: Regional View
```{r}
## generating a time series object
regional_obesity_prevalence_ts <- ts(regional_obesity_prevalence[,-1], start = 1975, frequency = 1)
## Charting the world obesity prevalence
dygraph(as.xts(regional_obesity_prevalence_ts),
main = "Obesity Prevalence by Region (%)") %>%
#dyOptions(colors = RColorBrewer::brewer.pal(7, "Set1")) %>%
dySeries("Africa", strokeWidth = 3, color = "orange") %>%
dySeries("Asia", strokeWidth = 3, color = "red") %>%
dySeries("Latin America and the Caribbean", strokeWidth = 3, color = "blue") %>%
dySeries("North America and Europe", strokeWidth = 3, color = "green") %>%
dySeries("Oceania", strokeWidth = 3, color = "purple") %>%
dyOptions(stackedGraph = FALSE) %>%
dyRangeSelector(height = 30) %>%
dyAxis("y", label = "Obesity Prevalence (%)") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE, width = 700) %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = FALSE)
```
U.S. & Top 5 Countries {data-navmenu="Obesity Prevalence"}
=====================================
row {.tabset data-width=1000}
-----------------------------------------------------------------------
### Annual Obesity Prevalence: U.S. and Top 5 Countries
```{r obj2-data-prep, include=FALSE}
obj2_data <- read_csv("Obesity/Obesity/share-of-adults-defined-as-obese.csv") %>%
rename(Prevalence = `Indicator:Prevalence of obesity among adults, BMI ≥ 30 (age-standardized estimate) (%) - Age Group:18+ years - Sex:Both sexes (%)`)
## selecting the U.S. data from the dataframe
US_obese_data <- obj2_data %>%
filter(Code == "USA") %>%
select(Year, Entity, Prevalence)
## Knowing the top 5 countries apart from the U.S.
top_5_countries_prevalence <- obj2_data %>%
filter(!Code == "USA") %>%
group_by(Entity) %>%
summarise(mean_prevalence = mean(Prevalence, na.rm = TRUE)) %>%
top_n(5)
## extracting the top 5 countries apart from the U.S.
extract_top_5_countries <- obj2_data %>%
filter(Entity %in% c("Cook Islands", "Marshall Islands", "Nauru", "Palau", "Tuvalu")) %>%
select(Year, Entity, Prevalence)
## stacking the U.S. prevalence dataframe with the top 5 countries
US_top_5_countries_prevalence <- bind_rows(US_obese_data, extract_top_5_countries) %>%
spread(Entity, Prevalence)
```
```{r}
## generating a time series object
US_top_5_countries_prevalence_ts <- ts(US_top_5_countries_prevalence[,-1], start = 1975, frequency = 1)
## Charting the world obesity prevalence
dygraph(as.xts(US_top_5_countries_prevalence_ts),
main = "U.S. & Top 5 Countries Obesity Prevalence (%)") %>%
#dyOptions(colors = RColorBrewer::brewer.pal(7, "Set1")) %>%
dySeries("Cook Islands", strokeWidth = 3, color = "orange") %>%
dySeries("Marshall Islands", strokeWidth = 3, color = "red") %>%
dySeries("Nauru", strokeWidth = 3, color = "blue") %>%
dySeries("Palau", strokeWidth = 3, color = "green") %>%
dySeries("Tuvalu", strokeWidth = 3, color = "purple") %>%
dySeries("United States", strokeWidth = 3, color = "brown") %>%
dyOptions(stackedGraph = FALSE) %>%
dyRangeSelector(height = 30) %>%
dyAxis("y", label = "Obesity Prevalence (%)") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE, width = 700) %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = FALSE)
```
U.S. & Top 5 Countries {data-navmenu="Overweight Prevalence"}
=====================================
row {.tabset data-width=1000}
-----------------------------------------------------------------------
### Annual Over-Weight Prevalence: U.S. and Top 5 Countries
```{r obj3_data_prep, include=FALSE}
obj3_data <- read_csv("Obesity/Obesity/share-of-adults-who-are-overweight.csv") %>%
rename(Prevalence = `Indicator:Prevalence of overweight among adults, BMI ≥ 25 (crude estimate) (%) - Age Group:18+ years - Sex:Both sexes (%)`)
## selecting the U.S. data from the dataframe
US_overWeight_data <- obj3_data %>%
filter(Code == "USA") %>%
select(Year, Entity, Prevalence)
## Knowing the top 5 countries apart from the U.S.
top_5_countries_overWeight_prevalence <- obj3_data %>%
filter(!Code == "USA") %>%
group_by(Entity) %>%
summarise(mean_prevalence = mean(Prevalence, na.rm = TRUE)) %>%
top_n(5)
## extracting the top 5 countries apart from the U.S.
extract_top_5_countries <- obj3_data %>%
filter(Entity %in% c("Cook Islands", "Marshall Islands", "Nauru", "Palau", "Tuvalu")) %>%
select(Year, Entity, Prevalence)
## stacking the U.S. prevalence dataframe with the top 5 countries
US_top_5_countries_overWeight_prevalence <- bind_rows(US_overWeight_data, extract_top_5_countries) %>%
spread(Entity, Prevalence)
```
```{r}
## generating a time series object
US_top_5_countries_overWeight_prevalence_ts <- ts(US_top_5_countries_overWeight_prevalence[,-1], start = 1975, frequency = 1)
## Charting the world obesity prevalence
dygraph(as.xts(US_top_5_countries_overWeight_prevalence_ts),
main = "U.S. & Top 5 Countries Over-Weight Prevalence (%)") %>%
#dyOptions(colors = RColorBrewer::brewer.pal(7, "Set2")) %>%
dySeries("Cook Islands", strokeWidth = 3, color = "orange") %>%
dySeries("Marshall Islands", strokeWidth = 3, color = "red") %>%
dySeries("Nauru", strokeWidth = 3, color = "blue") %>%
dySeries("Palau", strokeWidth = 3, color = "green") %>%
dySeries("Tuvalu", strokeWidth = 3, color = "purple") %>%
dySeries("United States", strokeWidth = 3, color = "brown") %>%
dyOptions(stackedGraph = FALSE) %>%
dyRangeSelector(height = 30) %>%
dyAxis("y", label = "Over-Weight Prevalence (%)") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE, width = 700) %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = FALSE)
```
Female {data-navmenu="Gender Based Obesity"}
=====================================
row {.tabset data-width=1000}
-----------------------------------------------------------------------
### Annual Female Obesity Prevalence: U.S. and Top 5 Countries
```{r obj4_data_prep, include=FALSE}
obj4_data <- read_csv("Obesity/Obesity/share-of-females-defined-as-obese.csv") %>%
rename(Prevalence = `Indicator:Prevalence of obesity among adults, BMI ≥ 30 (age-standardized estimate) (%) - Age Group:18+ years - Sex:Female (%)`)
## selecting the U.S. data from the dataframe
US_female_obese_data <- obj4_data %>%
filter(Code == "USA") %>%
select(Year, Entity, Prevalence)
## Knowing the top 5 countries apart from the U.S.
top_5_countries_female_obese_prevalence <- obj4_data %>%
filter(!Code == "USA") %>%
group_by(Entity) %>%
summarise(mean_prevalence = mean(Prevalence, na.rm = TRUE)) %>%
top_n(5)
## extracting the top 5 countries apart from the U.S.
extract_top_5_countries <- obj4_data %>%
filter(Entity %in% c("Cook Islands", "Marshall Islands", "Nauru", "Palau", "Samoa")) %>%
select(Year, Entity, Prevalence)
## stacking the U.S. prevalence dataframe with the top 5 countries
US_top_5_countries_female_obese_prevalence <- bind_rows(US_female_obese_data, extract_top_5_countries) %>%
spread(Entity, Prevalence)
```
```{r}
## generating a time series object
US_top_5_countries_female_obese_prevalence_ts <- ts(US_top_5_countries_female_obese_prevalence[,-1], start = 1975, frequency = 1)
## Charting the world obesity prevalence
dygraph(as.xts(US_top_5_countries_female_obese_prevalence_ts),
main = "U.S. & Top 5 Countries Female Obesity Prevalence (%)") %>%
#dyOptions(colors = RColorBrewer::brewer.pal(7, "Set2")) %>%
dySeries("Cook Islands", strokeWidth = 3, color = "orange") %>%
dySeries("Marshall Islands", strokeWidth = 3, color = "red") %>%
dySeries("Nauru", strokeWidth = 3, color = "blue") %>%
dySeries("Palau", strokeWidth = 3, color = "green") %>%
dySeries("Samoa", strokeWidth = 3, color = "purple") %>%
dySeries("United States", strokeWidth = 3, color = "brown") %>%
dyOptions(stackedGraph = FALSE) %>%
dyRangeSelector(height = 30) %>%
dyAxis("y", label = "Obesity Prevalence (%)") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE, width = 700) %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = FALSE)
```
### Annual Female Over-Weight Prevalence: U.S. and Top 5 Countries
```{r obj5_data_prep, include=FALSE}
obj5_data <- read_csv("Obesity/Obesity/share-of-females-defined-as-overweight.csv") %>%
rename(Prevalence = `Indicator:Prevalence of overweight among adults, BMI ≥ 25 (age-standardized estimate) (%) - Age Group:18+ years - Sex:Female (%)`)
## selecting the U.S. data from the dataframe
US_female_overWeight_data <- obj5_data %>%
filter(Code == "USA") %>%
select(Year, Entity, Prevalence)
## Knowing the top 5 countries apart from the U.S.
top_5_countries_female_overWeight_prevalence <- obj5_data %>%
filter(!Code == "USA") %>%
group_by(Entity) %>%
summarise(mean_prevalence = mean(Prevalence, na.rm = TRUE)) %>%
top_n(5)
## extracting the top 5 countries apart from the U.S.
extract_top_5_countries <- obj5_data %>%
filter(Entity %in% c("Cook Islands", "Marshall Islands", "Nauru", "Palau", "Tuvalu")) %>%
select(Year, Entity, Prevalence)
## stacking the U.S. prevalence dataframe with the top 5 countries
US_top_5_countries_female_overWeight_prevalence <- bind_rows(US_female_overWeight_data, extract_top_5_countries) %>%
spread(Entity, Prevalence)
```
```{r}
## generating a time series object
US_top_5_countries_female_overWeight_prevalence_ts <- ts(US_top_5_countries_female_overWeight_prevalence[,-1], start = 1975, frequency = 1)
## Charting the world obesity prevalence
dygraph(as.xts(US_top_5_countries_female_overWeight_prevalence_ts),
main = "U.S. & Top 5 Countries Female Over-Weight Prevalence (%)") %>%
#dyOptions(colors = RColorBrewer::brewer.pal(7, "Set2")) %>%
dySeries("Cook Islands", strokeWidth = 3, color = "orange") %>%
dySeries("Marshall Islands", strokeWidth = 3, color = "red") %>%
dySeries("Nauru", strokeWidth = 3, color = "blue") %>%
dySeries("Palau", strokeWidth = 3, color = "green") %>%
dySeries("Tuvalu", strokeWidth = 3, color = "purple") %>%
dySeries("United States", strokeWidth = 3, color = "brown") %>%
dyOptions(stackedGraph = FALSE) %>%
dyRangeSelector(height = 30) %>%
dyAxis("y", label = "Over-Weight Prevalence (%)") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE, width = 700) %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = FALSE)
```
Male {data-navmenu="Gender Based Obesity"}
=====================================
row {.tabset data-width=1000}
-----------------------------------------------------------------------
### Annual Male Obesity Prevalence: U.S. and Top 5 Countries
```{r obj6_data_prep, include=FALSE}
obj6_data <- read_csv("Obesity/Obesity/share-of-men-defined-as-obese.csv") %>%
rename(Prevalence = `Indicator:Prevalence of obesity among adults, BMI ≥ 30 (age-standardized estimate) (%) - Age Group:18+ years - Sex:Male (%)`)
## selecting the U.S. data from the dataframe
US_male_obese_data <- obj6_data %>%
filter(Code == "USA") %>%
select(Year, Entity, Prevalence)
## Knowing the top 5 countries apart from the U.S.
top_5_countries_male_obese_prevalence <- obj6_data %>%
filter(!Code == "USA") %>%
group_by(Entity) %>%
summarise(mean_prevalence = mean(Prevalence, na.rm = TRUE)) %>%
top_n(5)
## extracting the top 5 countries apart from the U.S.
extract_top_5_countries <- obj6_data %>%
filter(Entity %in% c("Cook Islands", "Marshall Islands", "Nauru", "Palau", "Tuvalu")) %>%
select(Year, Entity, Prevalence)
## stacking the U.S. prevalence dataframe with the top 5 countries
US_top_5_countries_male_obese_prevalence <- bind_rows(US_male_obese_data, extract_top_5_countries) %>%
spread(Entity, Prevalence)
```
```{r}
## generating a time series object
US_top_5_countries_male_obese_prevalence_ts <- ts(US_top_5_countries_male_obese_prevalence[,-1], start = 1975, frequency = 1)
## Charting the world obesity prevalence
dygraph(as.xts(US_top_5_countries_male_obese_prevalence_ts),
main = "U.S. & Top 5 Countries Male Obesity Prevalence (%)") %>%
#dyOptions(colors = RColorBrewer::brewer.pal(7, "Set2")) %>%
dySeries("Cook Islands", strokeWidth = 3, color = "orange") %>%
dySeries("Marshall Islands", strokeWidth = 3, color = "red") %>%
dySeries("Nauru", strokeWidth = 3, color = "blue") %>%
dySeries("Palau", strokeWidth = 3, color = "green") %>%
dySeries("Tuvalu", strokeWidth = 3, color = "purple") %>%
dySeries("United States", strokeWidth = 3, color = "brown") %>%
dyOptions(stackedGraph = FALSE) %>%
dyRangeSelector(height = 30) %>%
dyAxis("y", label = "Obesity Prevalence (%)") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE, width = 700) %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = FALSE)
```
### Annual Male Over-Weight Prevalence: U.S. and Top 5 Countries
```{r obj7_data_prep, include=FALSE}
obj7_data <- read_csv("Obesity/Obesity/share-of-men-defined-as-overweight.csv") %>%
rename(Prevalence = `Indicator:Prevalence of overweight among adults, BMI ≥ 25 (age-standardized estimate) (%) - Age Group:18+ years - Sex:Male (%)`)
## selecting the U.S. data from the dataframe
US_male_overWeight_data <- obj5_data %>%
filter(Code == "USA") %>%
select(Year, Entity, Prevalence)
## Knowing the top 5 countries apart from the U.S.
top_5_countries_male_overWeight_prevalence <- obj5_data %>%
filter(!Code == "USA") %>%
group_by(Entity) %>%
summarise(mean_prevalence = mean(Prevalence, na.rm = TRUE)) %>%
top_n(5)
## extracting the top 5 countries apart from the U.S.
extract_top_5_countries <- obj5_data %>%
filter(Entity %in% c("Cook Islands", "Marshall Islands", "Nauru", "Palau", "Tuvalu")) %>%
select(Year, Entity, Prevalence)
## stacking the U.S. prevalence dataframe with the top 5 countries
US_top_5_countries_male_overWeight_prevalence <- bind_rows(US_male_overWeight_data, extract_top_5_countries) %>%
spread(Entity, Prevalence)
```
```{r}
## generating a time series object
US_top_5_countries_male_overWeight_prevalence_ts <- ts(US_top_5_countries_male_overWeight_prevalence[,-1], start = 1975, frequency = 1)
## Charting the world obesity prevalence
dygraph(as.xts(US_top_5_countries_male_overWeight_prevalence_ts),
main = "U.S. & Top 5 Countries Male Over-Weight Prevalence (%)") %>%
#dyOptions(colors = RColorBrewer::brewer.pal(7, "Set2")) %>%
dySeries("Cook Islands", strokeWidth = 3, color = "orange") %>%
dySeries("Marshall Islands", strokeWidth = 3, color = "red") %>%
dySeries("Nauru", strokeWidth = 3, color = "blue") %>%
dySeries("Palau", strokeWidth = 3, color = "green") %>%
dySeries("Tuvalu", strokeWidth = 3, color = "purple") %>%
dySeries("United States", strokeWidth = 3, color = "brown") %>%
dyOptions(stackedGraph = FALSE) %>%
dyRangeSelector(height = 30) %>%
dyAxis("y", label = "Over-Weight Prevalence (%)") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE, width = 700) %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = FALSE)
```
Female {data-navmenu="Gender Based BMI"}
=====================================
row {.tabset data-width=1000}
-----------------------------------------------------------------------
### 2014 BMI in Adult Women
```{r obj8_data_prep}
obj8_data <- read_csv("Obesity/Obesity/mean-body-mass-index-bmi-in-adult-women.csv")
country_iso <- read_csv("countries_ISO.csv")
## selecting the required year i.e. 2014 from the dataframe
obj8_data_2014 <- obj8_data %>% filter(Year == 2014) %>%
select(-`Total population (Gapminder)`) %>%
rename(name = Entity, Mean_BMI = `(kg/m2)`)
obj8_data_2014_merged <- obj8_data_2014 %>% left_join(country_iso, by = c("name"= "Name")) %>%
mutate(Mean_BMI = round(Mean_BMI, 2))
## Map visualization for the 2014 mean BMI in Adult Women
options(highcharter.download_map_data = TRUE)
hcmap(map = "custom/world-highres2", data = obj8_data_2014_merged,
joinBy = c("hc-a2", "Code.y"), value = "Mean_BMI", name = "2014 BMI in Adult Women",
dataLabels = list(enabled = TRUE, format = "{point.name}"),
borderColor = "#FAFAFA", borderWidth = 0.1,
tooltip = list(valueSuffix = " kg/m2"),
download_map_data = FALSE) %>%
hc_title(text = "2014 BMI in Adult Women")
```
Male {data-navmenu="Gender Based BMI"}
=====================================
row {.tabset data-width=1000}
-----------------------------------------------------------------------
### 2014 BMI in Adult Men
```{r obj9_data_prep}
obj9_data <- read_csv("Obesity/Obesity/mean-body-mass-index-bmi-in-adult-males.csv")
country_iso <- read_csv("countries_ISO.csv")
## selecting the required year i.e. 2014 from the dataframe
obj9_data_2014 <- obj9_data %>% filter(Year == 2014) %>%
select(-`Total population (Gapminder)`) %>%
rename(`iso-a3` = Code, Mean_BMI = `(kg/m2)`)
obj9_data_2014_merged <- obj9_data_2014 %>% left_join(country_iso, by = c("Entity"= "Name")) %>%
mutate(Mean_BMI = round(Mean_BMI, 2))
hcmap(map = "custom/world-highres2", data = obj9_data_2014_merged,
joinBy = c("hc-a2", "Code"), value = "Mean_BMI", name = "2014 BMI in Adult Men",
dataLabels = list(enabled = TRUE, format = "{point.name}"),
borderColor = "#FAFAFA", borderWidth = 0.1,
tooltip = list(valueSuffix = " kg/m2"),
download_map_data = FALSE) %>%
hc_title(text = "2014 BMI in Adult Men")
```
Distribution & Correlation {data-navmenu="2016 Obesity Prevalence"}
=====================================
row {.tabset data-width=1000}
-----------------------------------------------------------------------
### 2016 Distribution of Obesity Prevalence in Female
```{r obj10_data_prep}
## reading the dataset
obj10_data <- read_csv("Obesity/Obesity/obesity-in-men-vs-obesity-in-women.csv")
## filtering the 2016 data and selecting the required fields
obj10_data_2016 <- obj10_data %>% filter(Year == 2016) %>%
select(`Share of women who are obese (%)`, `Share of men who are obese (%)`)
## plotting the density distribution of the obese prevalence in female : 2016
hchart(obj10_data_2016$`Share of women who are obese (%)`, type = "histogram", color = "#e60073", name = "Obese Female") %>%
hc_xAxis(title = list(text = "Obesity Band")) %>%
hc_yAxis(title = list(text = "Frequency")) %>%
hc_title(text = "2016 Distribution of Obesity Prevalence in Female")
```
### 2016 Distribution of Obesity Prevalence in Male
```{r}
## plotting the density distribution of the obese prevalence in male : 2016
hchart(obj10_data_2016$`Share of men who are obese (%)`, type = "histogram", color = "#b3ccff", name = "Obese Male") %>%
hc_xAxis(title = list(text = "Obesity Band")) %>%
hc_yAxis(title = list(text = "Frequency")) %>%
hc_title(text = "2016 Distribution of Obesity Prevalence in Male")
```
### Correlation Between Obesity Prevalence in Male & Female
```{r}
hchart(cor(obj10_data_2016, use = "pairwise.complete.obs")) %>%
hc_title(text = "Correlation Between Obesity Prevalence in Male & Female")
```
Female Forecast {data-navmenu="Gender Based BMI Forecast"}
=====================================
row {.tabset data-width=1000}
-----------------------------------------------------------------------
### U.S. Female BMI Category
```{r obj11-data-prep}
## Reading the dataset for the share of women by BMI categories
obj11_data <- read_csv("Obesity/Obesity/share-of-women-defined-as-underweight-healthy-overweight-or-obese.csv")
## filtering the U.S. BMI from the dataframe. Also, selecting the required fields
obj11_data_US <- obj11_data %>% filter(Code == "USA") %>%
select(-Entity, -Code)
## obtaining a tim series object
obj11_data_US_ts <- ts(obj11_data_US[,-1], start = 1975, frequency = 1)
## Charting the world obesity prevalence
dygraph(as.xts(obj11_data_US_ts),
main = "U.S. Female BMI Category (%)") %>%
#dyOptions(colors = RColorBrewer::brewer.pal(7, "Set2")) %>%
dySeries("Underweight (%)", strokeWidth = 3, color = "orange") %>%
dySeries("Healthy (%)", strokeWidth = 3, color = "red") %>%
dySeries("Overweight or Obese (%)", strokeWidth = 3, color = "blue") %>%
dyOptions(stackedGraph = FALSE) %>%
dyRangeSelector(height = 30) %>%
dyAxis("y", label = "% BMI Category") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE, width = 500) %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = FALSE)
```
### U.S. Women Underweight Share
```{r}
## selecting the Underweight field in the U.S. dataframe
obj11_data_US_underWeight <- obj11_data_US %>% select(Year, `Underweight (%)`)
## Creating a time series object
obj11_data_US_underWeight_ts <- ts(data = obj11_data_US_underWeight[, 2], start = 1975, frequency = 1)
## Modeling a univariate time series object using ARIMA and visualizing the series together with the forecast
x <- forecast(auto.arima(obj11_data_US_underWeight_ts), h = 5, level = 95)
hchart(x) %>%
hc_xAxis(title = list(text = "Date")) %>%
hc_yAxis(title = list(text = "Underweight Share (%)")) %>%
hc_title(text = "U.S. Women Underweight Share (%)")
```
### U.S. Women Healthy Share
```{r}
## selecting the healthy field in the U.S. dataframe
obj11_data_US_healthy <- obj11_data_US %>% select(Year, `Healthy (%)`)
## Creating a time series object
obj11_data_US_healthy_ts <- ts(data = obj11_data_US_healthy[, 2], start = 1975, frequency = 1)
## Modeling a univariate time series object using ARIMA and visualizing the series together with the forecast
y <- forecast(auto.arima(obj11_data_US_healthy_ts), h = 5, level = 95)
hchart(y) %>%
hc_xAxis(title = list(text = "Date")) %>%
hc_yAxis(title = list(text = "Healthy Share (%)")) %>%
hc_title(text = "U.S. Women Healthy Share (%)")
```
### U.S. Women Overweight or Obese Share
```{r}
## selecting the obese field in the U.S. dataframe
obj11_data_US_obese <- obj11_data_US %>% select(Year, `Overweight or Obese (%)`)
## Creating a time series object
obj11_data_US_obese_ts <- ts(data = obj11_data_US_obese[, 2], start = 1975, frequency = 1)
## Modeling a univariate time series object using ARIMA and visualizing the series together with the forecast
z <- forecast(auto.arima(obj11_data_US_obese_ts), h = 5, level = 95)
hchart(z) %>%
hc_xAxis(title = list(text = "Date")) %>%
hc_yAxis(title = list(text = "Obese or Overweight Share (%)")) %>%
hc_title(text = "U.S. Women Obese or Overweight Share (%)")
```
Male Forecast {data-navmenu="Gender Based BMI Forecast"}
=====================================
row {.tabset data-width=1000}
-----------------------------------------------------------------------
### U.S. Male BMI Category
```{r obj12-data-prep}
## Reading the dataset for the share of men by BMI categories
obj12_data <- read_csv("Obesity/Obesity/men-weight-categories.csv")
## filtering the U.S. BMI from the dataframe. Also, selecting the required fields
obj12_data_US <- obj12_data %>% filter(Code == "USA") %>%
select(-Entity, -Code)
## obtaining a time series object
obj12_data_US_ts <- ts(obj12_data_US[,-1], start = 1975, frequency = 1)
## Charting the world obesity prevalence
dygraph(as.xts(obj12_data_US_ts),
main = "U.S. Male BMI Category (%)") %>%
#dyOptions(colors = RColorBrewer::brewer.pal(7, "Set2")) %>%
dySeries("Underweight (%)", strokeWidth = 3, color = "orange") %>%
dySeries("Healthy (%)", strokeWidth = 3, color = "red") %>%
dySeries("Overweight or Obese (%)", strokeWidth = 3, color = "blue") %>%
dyOptions(stackedGraph = FALSE) %>%
dyRangeSelector(height = 30) %>%
dyAxis("y", label = "% BMI Category") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE, width = 500) %>%
dyHighlight(highlightCircleSize = 5,
highlightSeriesBackgroundAlpha = 0.2,
hideOnMouseOut = FALSE)
```
### U.S. Men Underweight Share
```{r}
## selecting the Underweight field in the U.S. dataframe
obj12_data_US_underWeight <- obj12_data_US %>% select(Year, `Underweight (%)`)
## Creating a time series object
obj12_data_US_underWeight_ts <- ts(data = obj12_data_US_underWeight[, 2], start = 1975, frequency = 1)
## Modeling a univariate time series object using ARIMA and visualizing the series together with the forecast
x <- forecast(auto.arima(obj12_data_US_underWeight_ts), h = 5, level = 95)
hchart(x) %>%
hc_xAxis(title = list(text = "Date")) %>%
hc_yAxis(title = list(text = "Underweight Share (%)")) %>%
hc_title(text = "U.S. Men Underweight Share (%)")
```
### U.S. Men Healthy Share
```{r}
## selecting the healthy field in the U.S. dataframe
obj12_data_US_healthy <- obj12_data_US %>% select(Year, `Healthy (%)`)
## Creating a time series object
obj12_data_US_healthy_ts <- ts(data = obj12_data_US_healthy[, 2], start = 1975, frequency = 1)
## Modeling a univariate time series object using ARIMA and visualizing the series together with the forecast
y <- forecast(auto.arima(obj12_data_US_healthy_ts), h = 5, level = 95)
hchart(y) %>%
hc_xAxis(title = list(text = "Date")) %>%
hc_yAxis(title = list(text = "Healthy Share (%)")) %>%
hc_title(text = "U.S. Men Healthy Share (%)")
```
### U.S. Men Overweight or Obese Share
```{r}
## selecting the obese field in the U.S. dataframe
obj12_data_US_obese <- obj12_data_US %>% select(Year, `Overweight or Obese (%)`)
## Creating a time series object
obj12_data_US_obese_ts <- ts(data = obj12_data_US_obese[, 2], start = 1975, frequency = 1)
## Modeling a univariate time series object using ARIMA and visualizing the series together with the forecast
z <- forecast(auto.arima(obj12_data_US_obese_ts), h = 5, level = 95)
hchart(z) %>%
hc_xAxis(title = list(text = "Date")) %>%
hc_yAxis(title = list(text = "Obese or Overweight Share (%)")) %>%
hc_title(text = "U.S. Men Obese or Overweight Share (%)")
```