From f0a394196955261ef46c6164e010e89c1f282506 Mon Sep 17 00:00:00 2001 From: Viveck Kingsley <166235217+viv3ckj@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:10:31 +0000 Subject: [PATCH 1/6] Added measures.py --- analysis/hyp_reg_measures.py | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 analysis/hyp_reg_measures.py diff --git a/analysis/hyp_reg_measures.py b/analysis/hyp_reg_measures.py new file mode 100644 index 0000000..5ba52a8 --- /dev/null +++ b/analysis/hyp_reg_measures.py @@ -0,0 +1,61 @@ +from ehrql import INTERVAL, case, create_measures, months, when, codelist_from_csv, create_dataset +from ehrql.tables.tpp import ( + clinical_events, + patients, + practice_registrations, +) + +# Hypertension codes +hyp_cod = codelist_from_csv( + "codelists/nhsd-primary-care-domain-refsets-hyp_cod.csv", + column="code" +) +# Hypertension resolved codes +hypres_cod = codelist_from_csv( + "codelists/nhsd-primary-care-domain-refsets-hypres_cod.csv", + column="code" +) + +index_date = "2024-03-31" +dataset = create_dataset() + +measures = create_measures() + +### variables ### + +# date of the most recent hypertension diagnosis up to and including the achievement date +hyplat_dat = ( + clinical_events.where(clinical_events.snomedct_code.is_in(hyp_cod) & clinical_events.date.is_on_or_before(INTERVAL.end_date)) + .sort_by(clinical_events.date) + .last_for_patient() + .date +) + +# date of the most recent hypertension diagnosis resolved code recorded after the most recent hypertension diagnosis and up to and including the achievement date +hypres_dat = ( + clinical_events.where(clinical_events.snomedct_code.is_in(hypres_cod) & clinical_events.date.is_on_or_before(INTERVAL.end_date)) + .sort_by(clinical_events.date) + .last_for_patient() + .date +) + +hyp_reg_r1 = hyplat_dat.is_not_null() & hypres_dat.is_null() | (hyplat_dat > hypres_dat) + +age = patients.age_on(INTERVAL.start_date) +age_band = case( + when((age >= 0) & (age < 20)).then("0-19"), + when((age >= 20) & (age < 40)).then("20-39"), + when((age >= 40) & (age < 60)).then("40-59"), + when((age >= 60) & (age < 80)).then("60-79"), + when(age >= 80).then("80+"), +) + +measures.define_measure( + name="resolved_diagnosis_by_age", + numerator=hypres_dat.is_not_null(), + denominator=patients.exists_for_patient(), + group_by={ + "age_band": age_band, + }, + intervals=months(12).starting_on("2023-04-01"), +) \ No newline at end of file From 059a966229b2fd27d0de4b6d7f2b6a208c925fce Mon Sep 17 00:00:00 2001 From: Viveck Kingsley <166235217+viv3ckj@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:10:45 +0000 Subject: [PATCH 2/6] Added measures to project.yaml --- project.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/project.yaml b/project.yaml index 1658493..f40c089 100644 --- a/project.yaml +++ b/project.yaml @@ -39,3 +39,11 @@ actions: outputs: highly_sensitive: cohort: output/dm/dm017_milan.csv.gz + + generate_hyp001_measures: + run: > + ehrql:v1 generate-measures analysis/hyp_reg_measures.py + --output output/hyp/hyp001_measures.csv + outputs: + moderately_sensitive: + measure: output/hyp/hyp001_measures.csv \ No newline at end of file From f3a8bcd32ed65c08d73f1148493ba7b5902b7d78 Mon Sep 17 00:00:00 2001 From: Viveck Kingsley <166235217+viv3ckj@users.noreply.github.com> Date: Thu, 15 Aug 2024 11:48:19 +0000 Subject: [PATCH 3/6] Added additional measures and groupings --- analysis/hyp_reg_measures.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/analysis/hyp_reg_measures.py b/analysis/hyp_reg_measures.py index 5ba52a8..20832e4 100644 --- a/analysis/hyp_reg_measures.py +++ b/analysis/hyp_reg_measures.py @@ -3,6 +3,7 @@ clinical_events, patients, practice_registrations, + addresses ) # Hypertension codes @@ -39,8 +40,6 @@ .date ) -hyp_reg_r1 = hyplat_dat.is_not_null() & hypres_dat.is_null() | (hyplat_dat > hypres_dat) - age = patients.age_on(INTERVAL.start_date) age_band = case( when((age >= 0) & (age < 20)).then("0-19"), @@ -50,12 +49,39 @@ when(age >= 80).then("80+"), ) +imd = addresses.for_patient_on(INTERVAL.end_date).imd_rounded +imd_quintile = case( + when((imd >=0) & (imd < int(32844 * 1 / 5))).then("1 (most deprived)"), + when(imd < int(32844 * 2 / 5)).then("2"), + when(imd < int(32844 * 3 / 5)).then("3"), + when(imd < int(32844 * 4 / 5)).then("4"), + when(imd < int(32844 * 5 / 5)).then("5 (least deprived)"), + otherwise="unknown" +) + + +# proportion of patients per month who were successfully treated for hypertension grouped by age band and index of multiple deprivation +# Could be a useful measure to look at which age groups / imd are likely to get a resolved diagnosis (access to care) measures.define_measure( name="resolved_diagnosis_by_age", numerator=hypres_dat.is_not_null(), denominator=patients.exists_for_patient(), group_by={ "age_band": age_band, + "imd": imd_quintile, + }, + intervals=months(6).starting_on("2023-04-01"), +) + +# proportion of patients per month who were diagnosed for hypertension grouped by age band and index of multiple deprivation +# Could be a useful measure to look at which age groups / imd are likely to get diagnosed(access to care and potentially contributing risk factors to positive diagnosis) +measures.define_measure( + name="diagnosis_by_age", + numerator=hyplat_dat.is_not_null(), + denominator=patients.exists_for_patient(), + group_by={ + "age_band": age_band, + "imd": imd_quintile, }, - intervals=months(12).starting_on("2023-04-01"), + intervals=months(6).starting_on("2023-04-01"), ) \ No newline at end of file From 7dd49f27f49edfd2a0dc2c3f8eceb64aae2d226b Mon Sep 17 00:00:00 2001 From: Viveck Kingsley <166235217+viv3ckj@users.noreply.github.com> Date: Tue, 20 Aug 2024 17:58:44 +0000 Subject: [PATCH 4/6] outputs produced and measures amended --- analysis/hyp_reg_measures.py | 38 +++++---- analysis/visualise_measures.R | 149 ++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 17 deletions(-) create mode 100644 analysis/visualise_measures.R diff --git a/analysis/hyp_reg_measures.py b/analysis/hyp_reg_measures.py index 20832e4..8f8297d 100644 --- a/analysis/hyp_reg_measures.py +++ b/analysis/hyp_reg_measures.py @@ -24,18 +24,22 @@ ### variables ### +selected_events = clinical_events.where( + clinical_events.date.is_on_or_before(INTERVAL.end_date) +) + # date of the most recent hypertension diagnosis up to and including the achievement date hyplat_dat = ( - clinical_events.where(clinical_events.snomedct_code.is_in(hyp_cod) & clinical_events.date.is_on_or_before(INTERVAL.end_date)) - .sort_by(clinical_events.date) + selected_events.where(selected_events.snomedct_code.is_in(hyp_cod)) + .sort_by(selected_events.date) .last_for_patient() .date ) # date of the most recent hypertension diagnosis resolved code recorded after the most recent hypertension diagnosis and up to and including the achievement date hypres_dat = ( - clinical_events.where(clinical_events.snomedct_code.is_in(hypres_cod) & clinical_events.date.is_on_or_before(INTERVAL.end_date)) - .sort_by(clinical_events.date) + selected_events.where(selected_events.snomedct_code.is_in(hypres_cod)) + .sort_by(selected_events.date) .last_for_patient() .date ) @@ -49,15 +53,15 @@ when(age >= 80).then("80+"), ) -imd = addresses.for_patient_on(INTERVAL.end_date).imd_rounded -imd_quintile = case( - when((imd >=0) & (imd < int(32844 * 1 / 5))).then("1 (most deprived)"), - when(imd < int(32844 * 2 / 5)).then("2"), - when(imd < int(32844 * 3 / 5)).then("3"), - when(imd < int(32844 * 4 / 5)).then("4"), - when(imd < int(32844 * 5 / 5)).then("5 (least deprived)"), - otherwise="unknown" -) +# imd = addresses.for_patient_on(INTERVAL.end_date).imd_rounded +# imd_quintile = case( +# when((imd >=0) & (imd < int(32844 * 1 / 5))).then("1 (most deprived)"), +# when(imd < int(32844 * 2 / 5)).then("2"), +# when(imd < int(32844 * 3 / 5)).then("3"), +# when(imd < int(32844 * 4 / 5)).then("4"), +# when(imd < int(32844 * 5 / 5)).then("5 (least deprived)"), +# otherwise="unknown" +# ) # proportion of patients per month who were successfully treated for hypertension grouped by age band and index of multiple deprivation @@ -68,9 +72,9 @@ denominator=patients.exists_for_patient(), group_by={ "age_band": age_band, - "imd": imd_quintile, + "sex": patients.sex, }, - intervals=months(6).starting_on("2023-04-01"), + intervals=months(12).starting_on("2023-04-01"), ) # proportion of patients per month who were diagnosed for hypertension grouped by age band and index of multiple deprivation @@ -81,7 +85,7 @@ denominator=patients.exists_for_patient(), group_by={ "age_band": age_band, - "imd": imd_quintile, + "sex": patients.sex, }, - intervals=months(6).starting_on("2023-04-01"), + intervals=months(12).starting_on("2023-04-01"), ) \ No newline at end of file diff --git a/analysis/visualise_measures.R b/analysis/visualise_measures.R new file mode 100644 index 0000000..2f73cb7 --- /dev/null +++ b/analysis/visualise_measures.R @@ -0,0 +1,149 @@ +library(tidyverse) +library(ggplot2) +library(gridExtra) # For arranging multiple plots + +# Load data +df_measures <- readr::read_csv( + here::here("output", "hyp", "hyp001_measures.csv") +) + +df_measures <- df_measures %>% + mutate( + start_date = as.Date(interval_start, format = "%Y-%m-%d"), + end_date = as.Date(interval_end, format = "%Y-%m-%d") + ) + +df_resolved <- df_measures %>% + filter(measure == "resolved_diagnosis_by_age") %>% + mutate(age_band = case_when( + is.na(age_band) ~ "(Missing)", + TRUE ~ age_band + ), + sex = case_when( + sex == "unknown" ~ "(Missing)", + TRUE ~ sex + ), + ratio = case_when( + is.na(ratio) ~ 0, + TRUE ~ ratio + ) + ) %>% + arrange(end_date) + +df_diagnosis <- df_measures %>% + filter(measure == "diagnosis_by_age") %>% + mutate(age_band = case_when( + is.na(age_band) ~ "(Missing)", + TRUE ~ age_band + ), + sex = case_when( + sex == "unknown" ~ "(Missing)", + TRUE ~ sex + ), + ratio = case_when( + is.na(ratio) ~ 0, + TRUE ~ ratio + ) + ) %>% + arrange(end_date) + +# df_resolved_tidy <- df_resolved %>% +# pivot_wider( +# id_cols = c(start_date, end_date, sex), +# names_from = age_band, +# values_from = ratio, +# values_fill = list(ratio = 0) +# ) %>% +# select( +# start_date, +# end_date, +# sex, +# `0-19`, +# `20-39`, +# `40-59`, +# `60-79`, +# `80+` +# ) %>% +# group_by(sex) %>% +# arrange(end_date) + + +# df_diagnosis_tidy <- df_diagnosis %>% +# pivot_wider( +# id_cols = c(start_date, end_date, sex), +# names_from = age_band, +# values_from = ratio, +# values_fill = list(ratio = 0) +# ) %>% +# select( +# start_date, +# end_date, +# sex, +# `0-19`, +# `20-39`, +# `40-59`, +# `60-79`, +# `80+` +# ) %>% +# group_by(sex) %>% +# arrange(end_date) + +# Filter out rows where age_band and sex is "Missing" +df_diagnosis_filtered <- df_diagnosis %>% + filter(age_band != "(Missing)" & sex != "(Missing)") + +# Create a list to store the plots +plot_list <- list() + +# Unique age bands +age_bands <- c("0-19", "20-39", "40-59", "60-79", "80+") + +# Generate plots for each age band +for (age_band in age_bands) { + # Filter data for the current age band + df_age_band <- df_diagnosis_filtered %>% + filter(age_band == !!age_band) + # Create the plot for the current age band + p <- ggplot(df_age_band, aes(x = end_date, y = ratio, color = sex, group = sex)) + + geom_line() + + labs(title = paste("Diagnosis Ratio for Age Band:", age_band), + x = "End Date", + y = "Diagnosis Ratio", + color = "Gender") + + theme_minimal() + + # Add the plot from loop to the list + plot_list[[age_band]] <- p +} + +"-------------" + +# Filter out rows where age_band and sex is "Missing" +df_resolved_filtered <- df_resolved %>% + filter(age_band != "(Missing)" & sex != "(Missing)") + +# Create a list to store the plots +plot_list2 <- list() + +# Unique age bands +age_bands <- c("0-19", "20-39", "40-59", "60-79", "80+") + +# Generate plots for each age band +for (age_band in age_bands) { + # Filter data for the current age band + df_age_band <- df_resolved_filtered %>% + filter(age_band == !!age_band) + # Create the plot for the current age band + p1 <- ggplot(df_age_band, aes(x = end_date, y = ratio, color = sex, group = sex)) + + geom_line() + + labs(title = paste("Resolved Diagnosis Ratio for Age Band:", age_band), + x = "End Date", + y = "Resolved Ratio", + color = "Gender") + + theme_minimal() + + # Add the plot from loop to the list + plot_list2[[age_band]] <- p1 +} + + From 5ea5ca50448eb18c418adc8b47ce09ea34d04b84 Mon Sep 17 00:00:00 2001 From: Viveck Kingsley <166235217+viv3ckj@users.noreply.github.com> Date: Tue, 27 Aug 2024 09:58:30 +0000 Subject: [PATCH 5/6] added plot graph action and save plots as png --- analysis/visualise_measures.R | 3 ++- project.yaml | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/analysis/visualise_measures.R b/analysis/visualise_measures.R index 2f73cb7..0ee5d35 100644 --- a/analysis/visualise_measures.R +++ b/analysis/visualise_measures.R @@ -115,6 +115,7 @@ for (age_band in age_bands) { # Add the plot from loop to the list plot_list[[age_band]] <- p } +ggsave("output/hyp/diagnosis_rates.png") "-------------" @@ -146,4 +147,4 @@ for (age_band in age_bands) { plot_list2[[age_band]] <- p1 } - +ggsave("output/hyp/resolved_rates.png") diff --git a/project.yaml b/project.yaml index f40c089..ee7dfc6 100644 --- a/project.yaml +++ b/project.yaml @@ -46,4 +46,16 @@ actions: --output output/hyp/hyp001_measures.csv outputs: moderately_sensitive: - measure: output/hyp/hyp001_measures.csv \ No newline at end of file + measure: output/hyp/hyp001_measures.csv + + generate_hyp001_plots: + run: > + r:latest + analysis/visualise_measures.R + --output output/hyp/resolved_rates.png + --output output/hyp/diagnosis_rates.png + needs: [generate_hyp001_measures] + outputs: + moderately_sensitive: + hyp_rates_resolved: output/hyp/resolved_rates.png + hyp_rates_diagnosis: output/hyp/diagnosis_rates.png \ No newline at end of file From 3f35b30df46264eccb90d5e7ecedd73ddb48bd40 Mon Sep 17 00:00:00 2001 From: Viveck Kingsley <166235217+viv3ckj@users.noreply.github.com> Date: Thu, 29 Aug 2024 11:19:49 +0000 Subject: [PATCH 6/6] Added suggested changes --- analysis/hyp_reg_measures.py | 35 ++---- analysis/visualise_measures.R | 214 +++++++++++----------------------- project.yaml | 6 +- 3 files changed, 82 insertions(+), 173 deletions(-) diff --git a/analysis/hyp_reg_measures.py b/analysis/hyp_reg_measures.py index 8f8297d..9427cc9 100644 --- a/analysis/hyp_reg_measures.py +++ b/analysis/hyp_reg_measures.py @@ -3,7 +3,6 @@ clinical_events, patients, practice_registrations, - addresses ) # Hypertension codes @@ -18,8 +17,6 @@ ) index_date = "2024-03-31" -dataset = create_dataset() - measures = create_measures() ### variables ### @@ -44,6 +41,9 @@ .date ) +# Rule for patients with a hypertension code that has not been resolved +hyp_reg_r1 = hyplat_dat.is_not_null() & hypres_dat.is_null() | (hyplat_dat > hypres_dat) + age = patients.age_on(INTERVAL.start_date) age_band = case( when((age >= 0) & (age < 20)).then("0-19"), @@ -53,23 +53,13 @@ when(age >= 80).then("80+"), ) -# imd = addresses.for_patient_on(INTERVAL.end_date).imd_rounded -# imd_quintile = case( -# when((imd >=0) & (imd < int(32844 * 1 / 5))).then("1 (most deprived)"), -# when(imd < int(32844 * 2 / 5)).then("2"), -# when(imd < int(32844 * 3 / 5)).then("3"), -# when(imd < int(32844 * 4 / 5)).then("4"), -# when(imd < int(32844 * 5 / 5)).then("5 (least deprived)"), -# otherwise="unknown" -# ) - +registration = practice_registrations.for_patient_on(INTERVAL.end_date) -# proportion of patients per month who were successfully treated for hypertension grouped by age band and index of multiple deprivation -# Could be a useful measure to look at which age groups / imd are likely to get a resolved diagnosis (access to care) +# Measure defining the rate of patients with unresolved hypertension per age band and sex measures.define_measure( - name="resolved_diagnosis_by_age", - numerator=hypres_dat.is_not_null(), - denominator=patients.exists_for_patient(), + name="diagnosis_by_age", + numerator=hyp_reg_r1 == True, + denominator=registration.exists_for_patient(), group_by={ "age_band": age_band, "sex": patients.sex, @@ -77,12 +67,11 @@ intervals=months(12).starting_on("2023-04-01"), ) -# proportion of patients per month who were diagnosed for hypertension grouped by age band and index of multiple deprivation -# Could be a useful measure to look at which age groups / imd are likely to get diagnosed(access to care and potentially contributing risk factors to positive diagnosis) +# Measure defining the rate of patients with resolved hypertension per age band and sex measures.define_measure( - name="diagnosis_by_age", - numerator=hyplat_dat.is_not_null(), - denominator=patients.exists_for_patient(), + name="resolved_by_age", + numerator=hyp_reg_r1 == False, + denominator=registration.exists_for_patient(), group_by={ "age_band": age_band, "sex": patients.sex, diff --git a/analysis/visualise_measures.R b/analysis/visualise_measures.R index 0ee5d35..bf87f69 100644 --- a/analysis/visualise_measures.R +++ b/analysis/visualise_measures.R @@ -1,150 +1,72 @@ library(tidyverse) -library(ggplot2) -library(gridExtra) # For arranging multiple plots +library(patchwork) +library(here) # Load data -df_measures <- readr::read_csv( - here::here("output", "hyp", "hyp001_measures.csv") -) - -df_measures <- df_measures %>% - mutate( - start_date = as.Date(interval_start, format = "%Y-%m-%d"), - end_date = as.Date(interval_end, format = "%Y-%m-%d") - ) - -df_resolved <- df_measures %>% - filter(measure == "resolved_diagnosis_by_age") %>% - mutate(age_band = case_when( - is.na(age_band) ~ "(Missing)", - TRUE ~ age_band - ), - sex = case_when( - sex == "unknown" ~ "(Missing)", - TRUE ~ sex - ), - ratio = case_when( - is.na(ratio) ~ 0, - TRUE ~ ratio - ) - ) %>% - arrange(end_date) - -df_diagnosis <- df_measures %>% +df_measures <- read_csv( + here("output", "hyp", "hyp001_measures.csv")) %>% + replace_na(list(age_band = "(Missing)")) %>% + mutate( + start_date = as.Date(interval_start, format = "%Y-%m-%d"), + end_date = as.Date(interval_end, format = "%Y-%m-%d"), + age_band = factor( + age_band, + levels = c("0-19", "20-39", "40-59", "60-79", "80+", "(Missing)"), + labels = c("0-19", "20-39", "40-59", "60-79", "80+", "(Missing)") + ) + ) + +plot_hypres <- df_measures %>% + filter(measure == "resolved_by_age") %>% + ggplot(aes( + x = end_date, + y = ratio, + colour = age_band, + )) + + geom_point() + + geom_line(alpha = .5) + + labs( + title = NULL, + x = NULL, + y = "Patients with hypertension resolved code", + colour = "Age Band" + ) + + scale_y_continuous( + labels = scales::label_percent(), + limits = c(0,1) + ) + + facet_wrap(~ factor( + sex, + levels = c("female", "male", "intersex", "unknown"), + labels = c("Female", "Male", "Intersex", "Unknown") + )) + +plot_hyp <- df_measures %>% filter(measure == "diagnosis_by_age") %>% - mutate(age_band = case_when( - is.na(age_band) ~ "(Missing)", - TRUE ~ age_band - ), - sex = case_when( - sex == "unknown" ~ "(Missing)", - TRUE ~ sex - ), - ratio = case_when( - is.na(ratio) ~ 0, - TRUE ~ ratio - ) - ) %>% - arrange(end_date) - -# df_resolved_tidy <- df_resolved %>% -# pivot_wider( -# id_cols = c(start_date, end_date, sex), -# names_from = age_band, -# values_from = ratio, -# values_fill = list(ratio = 0) -# ) %>% -# select( -# start_date, -# end_date, -# sex, -# `0-19`, -# `20-39`, -# `40-59`, -# `60-79`, -# `80+` -# ) %>% -# group_by(sex) %>% -# arrange(end_date) - - -# df_diagnosis_tidy <- df_diagnosis %>% -# pivot_wider( -# id_cols = c(start_date, end_date, sex), -# names_from = age_band, -# values_from = ratio, -# values_fill = list(ratio = 0) -# ) %>% -# select( -# start_date, -# end_date, -# sex, -# `0-19`, -# `20-39`, -# `40-59`, -# `60-79`, -# `80+` -# ) %>% -# group_by(sex) %>% -# arrange(end_date) - -# Filter out rows where age_band and sex is "Missing" -df_diagnosis_filtered <- df_diagnosis %>% - filter(age_band != "(Missing)" & sex != "(Missing)") - -# Create a list to store the plots -plot_list <- list() - -# Unique age bands -age_bands <- c("0-19", "20-39", "40-59", "60-79", "80+") - -# Generate plots for each age band -for (age_band in age_bands) { - # Filter data for the current age band - df_age_band <- df_diagnosis_filtered %>% - filter(age_band == !!age_band) - # Create the plot for the current age band - p <- ggplot(df_age_band, aes(x = end_date, y = ratio, color = sex, group = sex)) + - geom_line() + - labs(title = paste("Diagnosis Ratio for Age Band:", age_band), - x = "End Date", - y = "Diagnosis Ratio", - color = "Gender") + - theme_minimal() - - # Add the plot from loop to the list - plot_list[[age_band]] <- p -} -ggsave("output/hyp/diagnosis_rates.png") - -"-------------" - -# Filter out rows where age_band and sex is "Missing" -df_resolved_filtered <- df_resolved %>% - filter(age_band != "(Missing)" & sex != "(Missing)") - -# Create a list to store the plots -plot_list2 <- list() - -# Unique age bands -age_bands <- c("0-19", "20-39", "40-59", "60-79", "80+") - -# Generate plots for each age band -for (age_band in age_bands) { - # Filter data for the current age band - df_age_band <- df_resolved_filtered %>% - filter(age_band == !!age_band) - # Create the plot for the current age band - p1 <- ggplot(df_age_band, aes(x = end_date, y = ratio, color = sex, group = sex)) + - geom_line() + - labs(title = paste("Resolved Diagnosis Ratio for Age Band:", age_band), - x = "End Date", - y = "Resolved Ratio", - color = "Gender") + - theme_minimal() - - # Add the plot from loop to the list - plot_list2[[age_band]] <- p1 -} - -ggsave("output/hyp/resolved_rates.png") + ggplot(aes( + x = end_date, + y = ratio, + colour = age_band, + )) + + geom_point() + + geom_line(alpha = .5) + + labs( + title = NULL, + x = NULL, + y = "Patients with hypertension code", + colour = "Age Band" + ) + + scale_y_continuous( + labels = scales::label_percent(), + limits = c(0,1) + ) + + facet_wrap(~ factor( + sex, + levels = c("female", "male", "intersex", "unknown"), + labels = c("Female", "Male", "Intersex", "Unknown") + )) + +plot_hyp <- (plot_hyp / plot_hypres) + +plot_layout(guides = "collect") + +ggsave("output/hyp/hyp_plot.png", width = 8, height = 8) diff --git a/project.yaml b/project.yaml index ee7dfc6..420497d 100644 --- a/project.yaml +++ b/project.yaml @@ -52,10 +52,8 @@ actions: run: > r:latest analysis/visualise_measures.R - --output output/hyp/resolved_rates.png - --output output/hyp/diagnosis_rates.png + --output output/hyp/hyp_plot.png needs: [generate_hyp001_measures] outputs: moderately_sensitive: - hyp_rates_resolved: output/hyp/resolved_rates.png - hyp_rates_diagnosis: output/hyp/diagnosis_rates.png \ No newline at end of file + hyp_plot: output/hyp/hyp_plot.png \ No newline at end of file