Sleep Duration
ggplot(train, aes(x = health_condition, y = sleep_duration, fill = health_condition)) +
geom_boxplot(alpha = 0.7, outlier.alpha = 0.3) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(title = "Sleep Duration by Health Condition", y = "Sleep Duration", x = "") +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = health_condition, y = heart_rate, fill = health_condition)) +
geom_boxplot(alpha = 0.7, outlier.alpha = 0.3) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(title = "Heart Rate by Health Condition", y = "Heart Rate", x = "") +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = health_condition, y = bmi, fill = health_condition)) +
geom_boxplot(alpha = 0.7, outlier.alpha = 0.3) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "BMI",
y = "Density",
x = "BMI"
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = health_condition, y = calorie_expenditure, fill = health_condition)) +
geom_boxplot(alpha = 0.7, outlier.alpha = 0.3) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "Calorie Expenditure",
y = "Density",
x = "Calorie Expenditure"
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = health_condition, y = step_count, fill = health_condition)) +
geom_boxplot(alpha = 0.7, outlier.alpha = 0.3) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "Step Count",
y = "Density",
x = "Step Count"
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = health_condition, y = exercise_duration, fill = health_condition)) +
geom_boxplot(alpha = 0.7, outlier.alpha = 0.3) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "Exercise Duration",
y = "Density",
x = "Exercise Duration"
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = health_condition, y = water_intake, fill = health_condition)) +
geom_boxplot(alpha = 0.7, outlier.alpha = 0.3) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "Water Intake",
y = "Density",
x = "Water Intake"
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = factor(diet_type, levels = c("balanced", "non-veg", "veg")),
fill = factor(health_condition))) +
geom_bar(position = "fill") +
scale_y_continuous(labels = scales::percent) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "Diet Type",
y = "Count",
x = "Diet Type"
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = factor(stress_level, levels = c("low", "medium", "high")),
fill = factor(health_condition))) +
geom_bar(position = "fill") +
scale_y_continuous(labels = scales::percent) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "Stress Level",
y = "Count",
x = "Stress Level"
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = factor(sleep_quality, levels = c("poor", "average", "good")),
fill = factor(health_condition))) +
geom_bar(position = "fill") +
scale_y_continuous(labels = scales::percent) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "Sleep Quality",
y = "Count",
x = "Sleep Quality"
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = factor(gender, levels = c("female", "male", "other")),
fill = factor(health_condition))) +
geom_bar(position = "fill") +
scale_y_continuous(labels = scales::percent) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "Gender",
y = "Count",
x = "Gender"
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = factor(smoking_alcohol, levels = c("no", "occasional", "yes")),
fill = factor(health_condition))) +
geom_bar(position = "fill") +
scale_y_continuous(labels = scales::percent) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "Smoking / Alcohol Use",
y = "Count",
x = "Smoking / Alcohol"
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

ggplot(train, aes(x = factor(physical_activity_level, levels = c("sedentary", "moderate", "active")),
fill = factor(health_condition))) +
geom_bar(position = "fill") +
scale_y_continuous(labels = scales::percent) +
scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
scale_color_manual(values = c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7")) +
labs(
title = "Activity Levels",
y = "Count",
x = ""
) +
theme_minimal(base_size = 12, base_family = "sans") +
theme(
plot.title = element_text(face = "bold", size = 14, margin = margin(b = 4)),
plot.subtitle = element_text(color = "grey40", size = 11, margin = margin(b = 12)),
plot.caption = element_text(color = "grey60", size = 9, hjust = 0),
plot.margin = margin(16, 16, 16, 16),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.title = element_text(color = "grey30", size = 10),
axis.text = element_text(color = "grey30"),
axis.ticks.x = element_line(color = "grey80"),
legend.position = "bottom",
legend.title = element_blank()
)

cat_prop_table <- function(data, var) {
data |>
dplyr::count(.data[[var]], health_condition) |>
dplyr::group_by(.data[[var]]) |>
dplyr::mutate(pct = round(n / sum(n) * 100, 1)) |>
dplyr::select(-n) |>
tidyr::pivot_wider(names_from = health_condition, values_from = pct) |>
gt() |>
tab_header(title = paste("Health Condition % by", var))
}
cat_prop_table(train, "stress_level")
| Health Condition % by stress_level |
| at-risk |
fit |
unhealthy |
|
| 85.9 |
5.7 |
8.4 |
| high |
| 71.8 |
0.4 |
27.9 |
| low |
| 79.7 |
20.1 |
0.3 |
| medium |
| 99.4 |
0.3 |
0.3 |
cat_prop_table(train, "physical_activity_level")
| Health Condition % by physical_activity_level |
| at-risk |
fit |
unhealthy |
|
| 85.9 |
5.7 |
8.3 |
| active |
| 74.3 |
17.2 |
8.5 |
| moderate |
| 91.1 |
0.3 |
8.5 |
| sedentary |
| 91.7 |
0.2 |
8.0 |
cat_prop_table(train, "sleep_quality")
| Health Condition % by sleep_quality |
| at-risk |
fit |
unhealthy |
|
| 86.0 |
5.8 |
8.2 |
| average |
| 85.9 |
5.7 |
8.3 |
| good |
| 88.8 |
8.2 |
3.0 |
| poor |
| 83.0 |
3.5 |
13.6 |
cat_prop_table(train, "diet_type")
| Health Condition % by diet_type |
| at-risk |
fit |
unhealthy |
|
| 86.8 |
5.1 |
8.2 |
| balanced |
| 85.1 |
6.1 |
8.7 |
| non-veg |
| 86.8 |
5.2 |
8.1 |
| veg |
| 85.7 |
6.0 |
8.3 |
cat_prop_table(train, "gender")
| Health Condition % by gender |
| at-risk |
fit |
unhealthy |
|
| 85.8 |
5.6 |
8.6 |
| female |
| 85.7 |
5.7 |
8.6 |
| male |
| 85.7 |
6.3 |
8.0 |
| other |
| 86.2 |
5.3 |
8.5 |
cat_prop_table(train, "smoking_alcohol")
| Health Condition % by smoking_alcohol |
| at-risk |
fit |
unhealthy |
|
| 85.7 |
5.8 |
8.6 |
| no |
| 86.7 |
7.9 |
5.5 |
| occasional |
| 85.9 |
5.8 |
8.4 |
| yes |
| 85.1 |
3.7 |
11.2 |