This analysis explores how people spend their time based on the Indian Time Use Survey. We’ll look at everything from sleep and work to socializing and chores, breaking it down by age, gender, and location.
First up, let’s get the data loaded and prepped. We’ll be grouping hundreds of specific activities into broader, more understandable categories to make the analysis easier. The categorizations are based on the UN’s International Classification of Activities for Time Use Statistics (ICATUS 2016).
This chart shows how our average sleep duration changes as we age. Notice the decline during adolescence, followed by a more gradual change throughout adulthood.
sleep_vs_age_plot <- timeuse_df %>%
filter(activity == "Sleep", age < 90, age >= 6) %>%
group_by(person_id, age, mult) %>%
summarise(total_sleep_mins = sum(duration_mins, na.rm = TRUE),
.groups = 'drop') %>%
group_by(age) %>%
summarise(avg_sleep_weighted_mins = weighted.mean(total_sleep_mins, w = mult, na.rm = TRUE)) %>%
mutate(avg_sleep_hours = avg_sleep_weighted_mins / 60) %>%
ggplot(aes(x = age, y = avg_sleep_hours)) +
geom_smooth(
method = "loess",
se = TRUE,
color = "black",
fill = "gray80"
) +
scale_y_continuous(limits = c(8, 13), breaks = seq(8, 13, by = 1)) +
scale_x_continuous(breaks = seq(0, 90, by = 10), limits = c(6, 95)) +
labs(
title = "Average daily sleep across the ages",
x = "Age",
y = "Average Sleep (hours per day)",
caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath"),
plot.title = element_text(
family = "ath",
face = "bold",
size = 18,
margin = margin(b = 20)
),
plot.caption = element_text(
family = "ath",
size = 10,
color = "gray50"
),
axis.title = element_text(family = "ath", size = 12)
)
sleep_vs_age_plot## `geom_smooth()` using formula = 'y ~ x'
# --- Essential Sleep Only ---
night_sleep_vs_age_plot <- timeuse_df %>%
filter(activity_code == "Night sleep/essential sleep", age < 90, age >= 6) %>%
group_by(person_id, age, mult) %>%
summarise(total_sleep_mins = sum(duration_mins, na.rm = TRUE),
.groups = 'drop') %>%
group_by(age) %>%
summarise(avg_sleep_weighted_mins = weighted.mean(total_sleep_mins, w = mult, na.rm = TRUE)) %>%
mutate(avg_sleep_hours = avg_sleep_weighted_mins / 60) %>%
ggplot(aes(x = age, y = avg_sleep_hours)) +
geom_smooth(
method = "loess",
se = TRUE,
color = "navy", # Changed color to distinguish from the other plot
fill = "lightblue"
) +
scale_y_continuous(limits = c(7, 12), breaks = seq(7, 12, by = 1)) + # Adjusted limits for this data
scale_x_continuous(breaks = seq(0, 90, by = 10), limits = c(6, 95)) +
labs(
title = "Average daily 'Night Sleep / Essential Sleep' across the ages",
x = "Age",
y = "Average Essential Sleep (hours per day)",
caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath"),
plot.title = element_text(
family = "ath",
face = "bold",
size = 18,
margin = margin(b = 10) # Adjusted margin
),
plot.subtitle = element_text(
family = "ath",
size = 14,
margin = margin(b = 20),
color = "gray40"
),
plot.caption = element_text(
family = "ath",
size = 10,
color = "gray50"
),
axis.title = element_text(family = "ath", size = 12)
)
night_sleep_vs_age_plot## `geom_smooth()` using formula = 'y ~ x'
This “dumbbell” plot highlights the activities with the largest gender gaps across the entire population. It’s immediately clear that women handle a much larger share of unpaid domestic and caregiving work.
person_activity_totals <- timeuse_df %>%
filter(!is.na(activity) & activity != "Unclassified", gender %in% c("male", "female")) %>%
group_by(person_id, gender, mult, activity) %>%
summarise(total_duration_mins = sum(duration_mins, na.rm = TRUE), .groups = 'drop')
gender_summary_participants <- person_activity_totals %>%
group_by(gender, activity) %>%
summarise(
avg_hours_participants = weighted.mean(total_duration_mins, w = mult, na.rm = TRUE) / 60,
.groups = 'drop'
)
gender_summary_wide <- gender_summary_participants %>%
pivot_wider(names_from = gender, values_from = avg_hours_participants) %>%
mutate(gap = female - male) %>%
mutate(gap = case_when(
is.na(male) ~ female,
is.na(female) ~ -male,
TRUE ~ gap
)) %>%
filter(!is.na(gap)) %>%
slice_max(order_by = abs(gap), n = 15) %>%
mutate(activity = fct_reorder(activity, gap))
gender_gap_plot <- ggplot(gender_summary_wide, aes(y = activity)) +
geom_segment(aes(x = male, xend = female), color = "gray", linewidth = 1.5, alpha = 0.5) +
geom_point(aes(x = female, color = "Female"), size = 4) +
geom_point(aes(x = male, color = "Male"), size = 4) +
theme_fivethirtyeight() +
scale_x_continuous(labels = format_hours_minutes, breaks = pretty_breaks(n = 5)) +
scale_color_manual(name = "", values = c("Female" = "#0072B2", "Male" = "#D55E00")) +
labs(
title = "Unpaid work accounts for the largest gender gap in time use",
subtitle = "Comparing average daily hours for male and female participants",
x = "Average Hours Per Day (for participants)",
y = "",
caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme(
text = element_text(family = "ath"),
plot.title = element_text(family = "ath", size = 16, margin = margin(b = 10), hjust = 0.5),
plot.subtitle = element_text(family = "ath", size = 14, margin = margin(b = 20), color = "gray40", hjust = 0.5),
legend.position = "top"
)
gender_gap_plotperson_activity_totals_sector <- timeuse_df %>%
filter(!is.na(activity) & activity != "Unclassified") %>%
group_by(person_id, sector, mult, activity) %>%
summarise(total_duration_mins = sum(duration_mins, na.rm = TRUE), .groups = 'drop')
sector_summary_participants <- person_activity_totals_sector %>%
group_by(sector, activity) %>%
summarise(
avg_hours_participants = weighted.mean(total_duration_mins, w = mult, na.rm = TRUE) / 60,
.groups = 'drop'
)
sector_summary_wide <- sector_summary_participants %>%
pivot_wider(names_from = sector, values_from = avg_hours_participants) %>%
mutate(gap = Urban - Rural) %>%
mutate(gap = case_when(
is.na(Urban) ~ -Rural,
is.na(Rural) ~ Urban,
TRUE ~ gap
)) %>%
filter(!is.na(gap)) %>%
slice_max(order_by = abs(gap), n = 15) %>%
mutate(activity = fct_reorder(activity, gap))
sector_gap_plot <- ggplot(sector_summary_wide, aes(y = activity)) +
geom_segment(aes(x = Rural, xend = Urban), color = "gray", linewidth = 1.5, alpha = 0.5) +
geom_point(aes(x = Urban, color = "Urban"), size = 4) +
geom_point(aes(x = Rural, color = "Rural"), size = 4) +
theme_fivethirtyeight() +
scale_x_continuous(labels = format_hours_minutes, breaks = pretty_breaks(n = 5)) +
scale_color_manual(name = "", values = c("Urban" = "#0072B2", "Rural" = "#D55E00")) +
labs(
title = "Rural-urban divide in daily time use",
subtitle = "Comparing activities with the largest urban-rural disparities for participants",
x = "Average Hours Per Day (for participants)",
y = "",
caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme(
text = element_text(family = "ath"),
plot.title = element_text(family = "ath", size = 16, margin = margin(b = 10), hjust = 0.5),
plot.subtitle = element_text(family = "ath", size = 14, margin = margin(b = 20), color = "gray40", hjust = 0.5),
legend.position = "top"
)
sector_gap_plothigh_level_summary <- timeuse_df %>%
filter(!is.na(activity) & activity != "Unclassified") %>%
mutate(
activity_group = case_when(
activity == "Sleep" ~ "Sleep",
activity %in% c("Eating & Drinking", "Personal Hygiene & Health", "Receiving Care") ~ "Personal Care",
activity %in% c("Formal Employment", "Household Enterprise (Goods)", "Household Enterprise (Services)", "Work-Related Training", "Seeking Employment", "Setting up a Business") ~ "Paid Work",
activity %in% c("Food & Meal Management", "Cleaning & Maintenance", "Childcare & Instruction", "Shopping", "Agriculture & Fishing (Own-Use)", "Community Volunteering", "Direct Volunteering") ~ "Unpaid Work & Care",
activity %in% c("Formal Education", "Homework", "Additional Study") ~ "Learning",
TRUE ~ "Leisure, Social & Travel"
)
)
person_activity_group_summary <- high_level_summary %>%
group_by(person_id, activity_group) %>%
summarise(total_duration = sum(duration_mins, na.rm = TRUE), .groups = "drop")
stacking_order <- c("Sleep", "Personal Care", "Paid Work", "Unpaid Work & Care", "Learning", "Leisure, Social & Travel")
all_persons_age_group <- high_level_summary %>%
mutate(age_group = cut(
age,
breaks = c(5, 14, 24, 59, Inf),
labels = c("Children (6-14)", "Youth (15-24)", "Adults (25-59)", "Seniors (60+)"),
right = TRUE, include.lowest = TRUE
)) %>%
filter(!is.na(age_group)) %>%
distinct(person_id, age_group, mult)
age_group_summary_total <- all_persons_age_group %>%
tidyr::crossing(activity_group = unique(person_activity_group_summary$activity_group)) %>%
left_join(person_activity_group_summary, by = c("person_id", "activity_group")) %>%
mutate(total_duration = ifelse(is.na(total_duration), 0, total_duration)) %>%
group_by(age_group, activity_group) %>%
summarise(avg_hours = weighted.mean(total_duration, w = mult, na.rm = TRUE) / 60,
.groups = "drop") %>%
mutate(activity_group = factor(activity_group, levels = stacking_order))
age_strips_plot_total <- ggplot(age_group_summary_total,
aes(x = age_group, y = avg_hours, fill = activity_group)) +
geom_col(position = "fill", colour = "transparent") +
scale_y_continuous(labels = scales::percent) +
scale_fill_brewer(palette = "Dark2", name = "") +
labs(
title = "Share of a 24-hour Day for All Population, by Age Group",
x = "", y = "Percentage of Day", caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath"),
plot.title = element_text(family = "ath", size = 20, margin = margin(b = 10)),
legend.position = "bottom"
)
all_persons_age_gender_group <- high_level_summary %>%
filter(gender %in% c("male", "female")) %>%
mutate(age_group = cut(
age,
breaks = c(5, 14, 24, 59, Inf),
labels = c("Children (6-14)", "Youth (15-24)", "Adults (25-59)", "Seniors (60+)"),
right = TRUE, include.lowest = TRUE
)) %>%
filter(!is.na(age_group)) %>%
distinct(person_id, age_group, gender, mult)
age_gender_group_summary <- all_persons_age_gender_group %>%
tidyr::crossing(activity_group = unique(person_activity_group_summary$activity_group)) %>%
left_join(person_activity_group_summary, by = c("person_id", "activity_group")) %>%
mutate(total_duration = ifelse(is.na(total_duration), 0, total_duration)) %>%
group_by(age_group, gender, activity_group) %>%
summarise(avg_hours = weighted.mean(total_duration, w = mult, na.rm = TRUE) / 60,
.groups = "drop") %>%
mutate(activity_group = factor(activity_group, levels = stacking_order))
# --- MALES ---
age_strips_plot_male <- age_gender_group_summary %>%
filter(gender == "male") %>%
ggplot(aes(x = age_group, y = avg_hours, fill = activity_group)) +
geom_col(position = "fill", colour = "transparent") +
scale_y_continuous(labels = scales::percent) +
scale_fill_brewer(palette = "Dark2", name = "") +
labs(
title = "Share of a 24-hour Day for Males, by Age Group",
x = "", y = "Percentage of Day", caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath"),
plot.title = element_text(family = "ath", size = 20, margin = margin(b = 10)),
legend.position = "bottom"
)
# --- FEMALES ---
age_strips_plot_female <- age_gender_group_summary %>%
filter(gender == "female") %>%
ggplot(aes(x = age_group, y = avg_hours, fill = activity_group)) +
geom_col(position = "fill", colour = "transparent") +
scale_y_continuous(labels = scales::percent) +
scale_fill_brewer(palette = "Dark2", name = "") +
labs(
title = "Share of a 24-hour Day for Females, by Age Group",
x = "", y = "Percentage of Day", caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath"),
plot.title = element_text(family = "ath", size = 20, margin = margin(b = 10)),
legend.position = "bottom"
)
all_persons_age_sector_group <- high_level_summary %>%
mutate(age_group = cut(
age,
breaks = c(5, 14, 24, 59, Inf),
labels = c("Children (6-14)", "Youth (15-24)", "Adults (25-59)", "Seniors (60+)"),
right = TRUE, include.lowest = TRUE
)) %>%
filter(!is.na(age_group)) %>%
distinct(person_id, age_group, sector, mult)
age_sector_group_summary <- all_persons_age_sector_group %>%
tidyr::crossing(activity_group = unique(person_activity_group_summary$activity_group)) %>%
left_join(person_activity_group_summary, by = c("person_id", "activity_group")) %>%
mutate(total_duration = ifelse(is.na(total_duration), 0, total_duration)) %>%
group_by(age_group, sector, activity_group) %>%
summarise(avg_hours = weighted.mean(total_duration, w = mult, na.rm = TRUE) / 60,
.groups = "drop") %>%
mutate(activity_group = factor(activity_group, levels = stacking_order))
# --- Plot for Rural Population ---
age_strips_plot_rural <- age_sector_group_summary %>%
filter(sector == "Rural") %>%
ggplot(aes(x = age_group, y = avg_hours, fill = activity_group)) +
geom_col(position = "fill", colour = "transparent") +
scale_y_continuous(labels = scales::percent) +
scale_fill_brewer(palette = "Dark2", name = "") +
labs(
title = "Share of a 24-hour Day for Rural Population, by Age Group",
x = "", y = "Percentage of Day", caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath"),
plot.title = element_text(family = "ath", size = 20, margin = margin(b = 10)),
legend.position = "bottom"
)
# --- Plot for Urban Population ---
age_strips_plot_urban <- age_sector_group_summary %>%
filter(sector == "Urban") %>%
ggplot(aes(x = age_group, y = avg_hours, fill = activity_group)) +
geom_col(position = "fill", colour = "transparent") +
scale_y_continuous(labels = scales::percent) +
scale_fill_brewer(palette = "Dark2", name = "") +
labs(
title = "Share of a 24-hour Day for Urban Population, by Age Group",
x = "", y = "Percentage of Day", caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath"),
plot.title = element_text(family = "ath", size = 20, margin = margin(b = 10)),
legend.position = "bottom"
)
# --- Display the new plots ---
age_strips_plot_ruralactivity_colors <- c(
"Sleep" = "#1B9E77",
"Personal Care" = "#D95F02",
"Paid Work" = "#7570B3",
"Unpaid Work & Care" = "#E7298A",
"Learning" = "#666666FF", # Changed this from green to blue
"Leisure, Social & Travel" = "#E6AB02"
)
combined_gender_strips_plot <- age_gender_group_summary %>%
mutate(gender = str_to_title(gender)) %>%
ggplot(aes(x = gender, y = avg_hours, fill = activity_group)) +
geom_col(
position = "fill",
width = 0.8,
color = "white",
linewidth = 0.2
) +
facet_wrap(~ age_group, nrow = 1) +
scale_y_continuous(
labels = scales::percent_format(accuracy = 1),
breaks = seq(0, 1, by = 0.1)
) +
# Use scale_fill_manual to apply our custom colors
scale_fill_manual(values = activity_colors, name = "Activity Group:") +
labs(
title = "Share of a 24-Hour Day, by Gender and Age",
subtitle = "A comparison of how males and females spend their time across ages",
x = NULL,
y = "Percentage of Day",
caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath"),
plot.title = element_text(family = "ath", size = 20, margin = margin(b = 10)),
plot.subtitle = element_text(family = "ath", size = 14, margin = margin(b = 20), color = "gray40"),
legend.position = "bottom",
strip.text = element_text(face = "bold", size = 12),
axis.text.x = element_text(size = 11, face = "bold")
)
# Display the plot
combined_gender_strips_plotThis section tracks how children and youth spend their time.
person_daily_totals_youth <- timeuse_df %>%
filter(age >= 6 & age <= 24, !is.na(activity), activity != "Unclassified", gender %in% c("male", "female")) %>%
group_by(person_id, gender, mult, activity) %>%
summarise(total_duration_mins = sum(duration_mins, na.rm = TRUE), .groups = 'drop')
youth_gender_summary_participants <- person_daily_totals_youth %>%
group_by(gender, activity) %>%
summarise(avg_hours = weighted.mean(total_duration_mins, w = mult, na.rm = TRUE) / 60,
.groups = 'drop')
youth_gender_summary_wide <- youth_gender_summary_participants %>%
pivot_wider(names_from = gender, values_from = avg_hours) %>%
mutate(
male = ifelse(is.na(male), 0, male),
female = ifelse(is.na(female), 0, female),
total_time = female + male
) %>%
slice_max(order_by = total_time, n = 15) %>%
mutate(activity = fct_reorder(activity, total_time))
youth_dumbbell_plot <- ggplot(youth_gender_summary_wide, aes(y = activity)) +
geom_segment(
aes(x = male, xend = female),
color = "gray",
linewidth = 1.5,
alpha = 0.5
) +
geom_point(aes(x = female, color = "Female"), size = 4) +
geom_point(aes(x = male, color = "Male"), size = 4) +
theme_fivethirtyeight() +
scale_x_continuous(labels = format_hours_minutes, breaks = pretty_breaks(n = 5)) +
scale_color_manual(name = "",
values = c("Female" = "#0072B2", "Male" = "#D55E00")) +
labs(
title = "Top Time-Consuming Activities for Youth (Ages 6-24)",
subtitle = "Comparing average daily hours for male and female participants",
x = "Average Hours Per Day (for participants)",
y = "",
caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme(
text = element_text(family = "ath"),
plot.title = element_text(
family = "ath",
size = 16,
margin = margin(b = 10),
hjust = 0.5
),
plot.subtitle = element_text(
family = "ath",
size = 14,
margin = margin(b = 20),
color = "gray40",
hjust = 0.5
),
legend.position = "top"
)
youth_dumbbell_plotGender gaps in unpaid work emerge early.
youth_activities <- c(
"Formal Education", "Homework", "Additional Study", "Food & Meal Management",
"Cleaning & Maintenance", "Socializing & Communication", "Mass Media",
"Sports & Exercise", "Hobbies & Games"
)
# 1. First, SUM the total time per person for each activity
person_daily_totals_youth <- timeuse_df %>%
filter(
age >= 6 & age <= 24,
activity %in% youth_activities,
gender %in% c("male", "female")
) %>%
group_by(person_id, age, gender, sector, activity, mult) %>%
summarise(total_activity_mins = sum(duration_mins, na.rm = TRUE), .groups = 'drop')
# 2. Now, average those daily totals for participants
youth_summary <- person_daily_totals_youth %>%
group_by(age, gender, sector, activity) %>%
summarise(avg_hours = weighted.mean(total_activity_mins, w = mult, na.rm = TRUE) / 60,
.groups = "drop")
youth_gender_trends_plot <- ggplot(youth_summary, aes(x = age, y = avg_hours, color = gender)) +
geom_smooth(se = FALSE, size = 1.2) +
facet_wrap( ~ activity, scales = "free", ncol = 3) +
scale_y_continuous(labels = format_hours_minutes, breaks = pretty_breaks(n = 4)) +
scale_color_manual(name = "Gender",
values = c("female" = "#0072B2", "male" = "#D55E00")) +
labs(
title = "Average daily hours on key activities for ages 6-24, by gender",
x = "Age (years)",
y = "Average Hours Per Day",
caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme(
text = element_text(family = "ath"),
plot.title = element_text(
family = "ath",
size = 20,
margin = margin(b = 10)
),
strip.text = element_text(face = "bold", size = 11, hjust = 0),
legend.position = "bottom"
)## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
all_youth_by_sector <- timeuse_df %>%
filter(age >= 6 & age <= 24) %>%
distinct(person_id, age, sector, mult)
youth_person_summary_sector <- timeuse_df %>%
filter(age >= 6 & age <= 24, activity %in% youth_activities) %>%
group_by(person_id, activity) %>%
summarise(total_duration_mins = sum(duration_mins, na.rm = TRUE), .groups = "drop")
youth_sector_summary <- all_youth_by_sector %>%
tidyr::crossing(activity = youth_activities) %>%
left_join(youth_person_summary_sector, by = c("person_id", "activity")) %>%
mutate(total_duration_mins = ifelse(is.na(total_duration_mins), 0, total_duration_mins)) %>%
group_by(age, sector, activity) %>%
summarise(avg_hours = weighted.mean(total_duration_mins, w = mult, na.rm = TRUE) / 60,
.groups = "drop")
youth_sector_trends_plot <- ggplot(youth_sector_summary, aes(x = age, y = avg_hours, color = sector)) +
geom_smooth(se = FALSE, size = 1.2) +
facet_wrap(~ activity, scales = "free", ncol = 3) +
scale_y_continuous(labels = format_hours_minutes, breaks = pretty_breaks(n = 4)) +
scale_color_manual(name = "Sector", values = c("Urban" = "#0072B2", "Rural" = "#D55E00")) +
labs(
title = "Urban vs. Rural Time Use for Ages 6-24",
subtitle = "Comparing average daily hours spent on key activities by sector",
x = "Age (years)", y = "Average Hours Per Day",
caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath"),
plot.title = element_text(family = "ath", size = 20, margin = margin(b = 10)),
plot.subtitle = element_text(family = "ath", size = 14, margin = margin(b = 20), color = "gray40"),
strip.text = element_text(face = "bold", size = 11, hjust = 0),
legend.position = "bottom"
)
youth_sector_trends_plot## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
youth_activities <- c(
"Formal Education",
"Homework",
"Additional Study",
"Food & Meal Management",
"Cleaning & Maintenance",
"Socializing & Communication",
"Mass Media",
"Sports & Exercise",
"Hobbies & Games"
)
# 1. First, SUM the total time per person for each activity
person_daily_totals <- timeuse_df %>%
filter(
age >= 6 & age <= 24,
activity %in% youth_activities,
gender %in% c("male", "female")
) %>%
group_by(person_id, age, gender, sector, activity, mult) %>%
summarise(total_activity_mins = sum(duration_mins, na.rm = TRUE), .groups = 'drop')
# 2. Now, average those daily totals
youth_summary <- person_daily_totals %>%
group_by(age, gender, sector, activity) %>%
summarise(avg_hours = weighted.mean(total_activity_mins, w = mult, na.rm = TRUE) / 60,
.groups = "drop")
# --- Plot for Rural Youth (Corrected) ---
rural_youth_plot <- youth_summary %>%
filter(sector == "Rural") %>%
ggplot(aes(x = age, y = avg_hours, color = gender)) +
geom_smooth(se = FALSE, size = 1.2) +
facet_wrap(~ activity, ncol = 3, scales = "free_y") +
scale_color_manual(name = "Gender:", values = c("female" = "#0072B2", "male" = "#D55E00")) +
scale_y_continuous(labels = format_hours_minutes, breaks = pretty_breaks(n = 3)) +
labs(
title = "Activity Trends for Rural Youth (Ages 6-24)",
subtitle = "Comparing total daily time use between male and female participants.",
x = "Age (years)",
y = "Average Hours Per Day (for participants)",
caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath", color = "gray20"),
plot.title = element_text(size = 26, face = "bold", margin = margin(b = 10), hjust = 0),
plot.subtitle = element_text(size = 18, margin = margin(b = 25), color = "gray40", hjust = 0),
plot.caption = element_text(size = 12, color = "gray50"),
strip.text = element_text(face = "bold", size = 12, hjust = 0.5),
axis.title = element_text(size = 14),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom"
)
# --- Plot for Urban Youth (Corrected) ---
urban_youth_plot <- youth_summary %>%
filter(sector == "Urban") %>%
ggplot(aes(x = age, y = avg_hours, color = gender)) +
geom_smooth(se = FALSE, size = 1.2) +
facet_wrap(~ activity, ncol = 3, scales = "free_y") +
scale_color_manual(name = "Gender:", values = c("female" = "#0072B2", "male" = "#D55E00")) +
scale_y_continuous(labels = format_hours_minutes, breaks = pretty_breaks(n = 3)) +
labs(
title = "Activity Trends for Urban Youth (Ages 6-24)",
subtitle = "Comparing total daily time use between male and female participants.",
x = "Age (years)",
y = "Average Hours Per Day (for participants)",
caption = "Source: MoSPI Time Use Survey, 2024"
) +
theme_fivethirtyeight() +
theme(
text = element_text(family = "ath", color = "gray20"),
plot.title = element_text(size = 26, face = "bold", margin = margin(b = 10), hjust = 0),
plot.subtitle = element_text(size = 18, margin = margin(b = 25), color = "gray40", hjust = 0),
plot.caption = element_text(size = 12, color = "gray50"),
strip.text = element_text(face = "bold", size = 12, hjust = 0.5),
axis.title = element_text(size = 14),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "bottom"
)
rural_youth_plot## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
dir.create("exports", showWarnings = FALSE)
export_theme <- theme(
plot.title = element_text(size = 58),
plot.subtitle = element_text(size = 42),
plot.caption = element_text(size = 24),
axis.title = element_text(size = 38),
axis.text = element_text(size = 28),
legend.text = element_text(size = 28),
legend.title = element_text(size = 26),
strip.text = element_text(size = 38)
)
ggsave(filename = "exports/01_sleep_vs_age.png",
plot = sleep_vs_age_plot + export_theme,
width = 10, height = 8, dpi = 300, units = "in")## `geom_smooth()` using formula = 'y ~ x'
ggsave(filename = "exports/02_gender_gap_top15.png",
plot = gender_gap_plot + export_theme,
width = 10, height = 10, dpi = 300, units = "in")
ggsave(filename = "exports/03_sector_gap_top15.png",
plot = sector_gap_plot + export_theme,
width = 10, height = 10, dpi = 300, units = "in")
ggsave(filename = "exports/04_age_strips_total.png",
plot = age_strips_plot_total + export_theme,
width = 12, height = 9, dpi = 300, units = "in")
ggsave(filename = "exports/05_age_strips_male.png",
plot = age_strips_plot_male + export_theme,
width = 12, height = 9, dpi = 300, units = "in")
ggsave(filename = "exports/06_age_strips_female.png",
plot = age_strips_plot_female + export_theme,
width = 12, height = 9, dpi = 300, units = "in")
ggsave(filename = "exports/07_youth_top15_dumbbell.png",
plot = youth_dumbbell_plot + export_theme,
width = 10, height = 10, dpi = 300, units = "in")
ggsave(filename = "exports/08_youth_trends_by_gender.png",
plot = youth_gender_trends_plot + export_theme,
width = 12, height = 10, dpi = 300, units = "in")## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ggsave(filename = "exports/09_youth_trends_by_sector.png",
plot = youth_sector_trends_plot + export_theme,
width = 12, height = 10, dpi = 300, units = "in")## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ggsave(filename = "exports/10_rural_youth_trends.png",
plot = rural_youth_plot + export_theme,
width = 12, height = 10, dpi = 300, units = "in")## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ggsave(filename = "exports/11_urban_youth_trends.png",
plot = urban_youth_plot + export_theme,
width = 12, height = 10, dpi = 300, units = "in")## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ggsave(filename = "exports/12_age_strips_rural.png",
plot = age_strips_plot_rural + export_theme,
width = 12, height = 9, dpi = 300, units = "in")
ggsave(filename = "exports/13_age_strips_urban.png",
plot = age_strips_plot_urban + export_theme,
width = 12, height = 9, dpi = 300, units = "in")
ggsave(filename = "exports/14_essential_sleep.png",
plot = night_sleep_vs_age_plot + export_theme,
width = 12, height = 9, dpi = 300, units = "in")## `geom_smooth()` using formula = 'y ~ x'
ggsave(filename = "exports/15_combined_gender_age_strips.png",
plot = combined_gender_strips_plot + export_theme,
width = 12, height = 9, dpi = 300, units = "in")zip_file <- "time_use_analysis_bundle.zip"
files_to_zip <- c(
list.files("exports", full.names = TRUE, pattern = "\\.png$"),
"time-use-analysis.Rmd"
)
zip::zip(zipfile = zip_file, files = files_to_zip, mode = "cherry-pick")
download_file(
path = zip_file,
output_name = "Download Analysis Bundle (ZIP)",
button_label = "Download Bundle",
button_type = "success",
has_icon = TRUE,
icon = "fa fa-download",
self_contained = TRUE
)