Skip to content

Commit

Permalink
Added tables for PM2.5,NO2 and Physical Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
berdikhanova committed Nov 6, 2024
1 parent 5259790 commit 15641b7
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions presentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library(ggplot2)
library(esquisse)
library(dplyr)
library(stringr)
library(gt)

## Data baseline year for reference and scenario

Expand Down Expand Up @@ -319,6 +320,102 @@ mmet_imd <- ggplot(exposure, aes(x = imd, y = total_mmetHr, fill = scenario)) +
legend.text = element_text(face = "bold"),
legend.title = element_text(face = "bold"))

# PM2.5 Table
pm25_table <- exposure %>%
group_by(scenario) %>%
summarize(
Mean = round(mean(exposure_normalised_pm25), 2),
`5th` = round(quantile(exposure_normalised_pm25, 0.05), 2),
`25th` = round(quantile(exposure_normalised_pm25, 0.25), 2),
`35th` = round(quantile(exposure_normalised_pm25, 0.35), 2),
`50th` = round(quantile(exposure_normalised_pm25, 0.5), 2),
`95th` = round(quantile(exposure_normalised_pm25, 0.95), 2),
Median = round(median(exposure_normalised_pm25), 2),
.groups = 'drop'
) %>%
mutate(
`Change (%)` = round((Median - Median[scenario == "Baseline"]) / Median[scenario == "Baseline"] * 100, 2),
Type = "PM2.5"
)

# NO2 Table
no2_table <- exposure %>%
group_by(scenario) %>%
summarize(
Mean = round(mean(exposure_normalised_no2), 2),
`5th` = round(quantile(exposure_normalised_no2, 0.05), 2),
`25th` = round(quantile(exposure_normalised_no2, 0.25), 2),
`35th` = round(quantile(exposure_normalised_no2, 0.35), 2),
`50th` = round(quantile(exposure_normalised_no2, 0.5), 2),
`95th` = round(quantile(exposure_normalised_no2, 0.95), 2),
Median = round(median(exposure_normalised_no2), 2),
.groups = 'drop'
) %>%
mutate(
`Change (%)` = round((Median - Median[scenario == "Baseline"]) / Median[scenario == "Baseline"] * 100, 2),
Type = "NO2"
)

# Physical Activity (MMET) Table
mmet_table <- exposure %>%
group_by(scenario) %>%
summarize(
Mean = round(mean(total_mmetHr), 2),
`5th` = round(quantile(total_mmetHr, 0.05), 2),
`25th` = round(quantile(total_mmetHr, 0.25), 2),
`35th` = round(quantile(total_mmetHr, 0.35), 2),
`50th` = round(quantile(total_mmetHr, 0.5), 2),
`95th` = round(quantile(total_mmetHr, 0.95), 2),
Median = round(median(total_mmetHr), 2),
.groups = 'drop'
) %>%
mutate(
`Change (%)` = round((Median - Median[scenario == "Baseline"]) / Median[scenario == "Baseline"] * 100, 2),
Type = "Physical Activity"
)

combined_table <- bind_rows(pm25_table, no2_table, mmet_table) %>%
arrange(Type, scenario) %>%
gt() %>%
tab_row_group(
label = md("**PM2.5**"),
rows = Type == "PM2.5"
) %>%
tab_row_group(
label = md("**NO2**"),
rows = Type == "NO2"
) %>%
tab_row_group(
label = md("**Physical Activity**"),
rows = Type == "Physical Activity"
) %>%
cols_hide(columns = "Type") %>%
cols_label(
scenario = "",
Mean = "Mean",
`5th` = "5th Percentile",
`25th` = "25th Percentile",
`35th` = "35th Percentile",
`50th` = "50th Percentile",
`95th` = "95th Percentile",
Median = "Median",
`Change (%)` = "Change (%)"
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_column_labels()
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_row_groups()) %>%
tab_header(
title = "Summary Statistics of Individual Exposures",
subtitle = "The change is calculated as percentage difference with the baseline scenario") %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_title())

combined_table

############################ Health ##################################################

Expand Down

0 comments on commit 15641b7

Please sign in to comment.