Skip to content

Viv3ckj/update graphs #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions analysis/measures_definition_pf_codes_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
when(age.is_null()).then("Missing"),
)


# IMD groupings for IMD breakdown
imd = addresses.for_patient_on(INTERVAL.start_date).imd_rounded
max_imd = 32844
Expand Down
4 changes: 1 addition & 3 deletions lib/functions/function_plot_measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ plot_measures <- function(
theme(
legend.position = legend_position,
plot.title = element_text(hjust = 0.5)
) +

scale_colour_brewer(palette = "Set1")
)

# Automatically change y scale depending selected value
if (rlang::as_label(enquo(select_value)) %in% c("numerator", "denominator")) {
Expand Down
62 changes: 33 additions & 29 deletions reports/pharmacy_first_report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ if (Sys.getenv("OPENSAFELY_BACKEND") != "") {

# Define dictionaries with tidy names and mappings for measures
pf_measures_name_dict <- list(
# blood_pressure_service = "Blood Pressure Service",
# contraception_service = "Contraception Service",
consultation_service = "Consultation Service",
pharmacy_first_service = "Pharmacy First Service",
combined_service = "Pharmacy First Services",
combined_pf_service = "Pharmacy First Services",
acute_otitis_media = "Acute Otitis Media",
herpes_zoster = "Herpes Zoster",
acute_sinusitis = "Acute Sinusitis",
Expand All @@ -49,8 +47,6 @@ pf_measures_name_dict <- list(
)

pf_measures_name_mapping <- list(
# blood_pressure_service = "clinical_service",
# contraception_service = "clinical_service",
consultation_service = "clinical_service",
pharmacy_first_service = "clinical_service",
combined_pf_service = "pharmacy_first_services",
Expand Down Expand Up @@ -111,6 +107,13 @@ df_measures$region <- factor(

df_measures <- df_measures %>%
mutate(sex = factor(sex, levels = c("female", "male"), labels = c("Female", "Male")))

df_measures$age_band[is.na(df_measures$age_band)] <- "Missing"

gradient_palette <- c("#001F4D", "#0056B3", "#007BFF", "#66B3E2", "#A4D8E1", "grey")
region_palette <- c("red", "navy", "#018701", "#ffa600ca", "purple", "brown", "#f4a5b2", "cyan", "green", "grey")
ethnicity_palette <- c("#42db0188", "#0056B3", "#ff0000c2", "#a52a2a5a", "purple", "grey")
sex_palette <- c("red", "blue")
```

# Background
Expand All @@ -137,7 +140,7 @@ Links to the codelist for each analysis can be found beneath the relevant sectio

### Total population

```{r, message=FALSE, warning=FALSE}
```{r, message=FALSE, warning=FALSE, fig.height=8, fig.width=8}
# Select measures and breakdown
df_measures_selected <- df_measures %>%
filter(measure_desc == "clinical_service") %>%
Expand All @@ -150,11 +153,11 @@ plot_measures(
select_interval_date = interval_end,
colour_var = NULL,
guide_nrow = 1,
facet_wrap = FALSE,
facet_var = NULL,
facet_wrap = TRUE,
facet_var = measure,
title = "Number of consultations for each clinical service per month",
y_label = "Number of codes for consultations",
)
)
```

### Breakdown by age
Expand All @@ -176,7 +179,8 @@ plot_measures(
facet_var = measure,
title = "Number of consultations for each clinical service by age band per month",
y_label = "Number of codes for consultations",
)
) + scale_color_manual(values = gradient_palette)

```

### Breakdown by sex
Expand All @@ -198,7 +202,7 @@ plot_measures(
facet_var = measure,
title = "Number of consultations for each clinical service by sex per month",
y_label = "Number of codes for consultations",
)
) + scale_color_manual(values = sex_palette)
```

### Breakdown by IMD
Expand All @@ -220,7 +224,7 @@ plot_measures(
facet_var = measure,
title = "Number of consultations for each clinical service by IMD per month",
y_label = "Number of codes for consultations",
)
) + scale_color_manual(values = gradient_palette)
```

### Breakdown by region
Expand All @@ -242,12 +246,12 @@ plot_measures(
facet_var = measure,
title = "Number of consultations for each clinical service by region per month",
y_label = "Number of codes for consultations",
)
) + scale_color_manual(values = region_palette)
```

### Clinical Services by ethnicity
### Breakdown by ethnicity

```{r, message=FALSE, warning=FALSE}
```{r, message=FALSE, warning=FALSE, fig.height=8, fig.width=8}
# Select measures and breakdown
df_measures_selected <- df_measures %>%
filter(measure_desc == "pharmacy_first_services") %>%
Expand All @@ -264,7 +268,7 @@ plot_measures(
facet_var = measure,
title = "Number of consultations for each clinical service by ethnicity per month",
y_label = "Number of codes for consultations",
)
) + scale_color_manual(values = ethnicity_palette)
```

## Clinical Condition
Expand All @@ -274,7 +278,7 @@ Here we show the number of consultations for each of the Pharmacy First Clinical

### Total population

```{r, message=FALSE, warning=FALSE}
```{r, message=FALSE, warning=FALSE, fig.height=8, fig.width=8}
# Select measures and breakdown
df_measures_selected <- df_measures %>%
filter(measure_desc == "clinical_condition") %>%
Expand All @@ -286,16 +290,16 @@ plot_measures(
select_value = numerator,
select_interval_date = interval_end,
guide_nrow = 1,
facet_wrap = FALSE,
facet_var = NULL,
facet_wrap = TRUE,
facet_var = measure,
title = "Number of consultations for each clinical condition per month",
y_label = "Number of codes for consultations",
)
```

### Breakdown by age

```{r, message=FALSE, warning=FALSE, fig.height=15, fig.width=8}
```{r, message=FALSE, warning=FALSE, fig.height=8, fig.width=8}
# Select measures and breakdown
df_measures_selected <- df_measures %>%
filter(measure_desc == "clinical_condition") %>%
Expand All @@ -312,12 +316,12 @@ plot_measures(
facet_var = measure,
title = "Number of consultations for each clinical condition by age band per month",
y_label = "Number of codes for consultations",
)
) + scale_color_manual(values = gradient_palette)
```

### Breakdown by sex

```{r, message=FALSE, warning=FALSE, fig.height=15, fig.width=8}
```{r, message=FALSE, warning=FALSE, fig.height=8, fig.width=8}
# Select measures and breakdown
df_measures_selected <- df_measures %>%
filter(measure_desc == "clinical_condition") %>%
Expand All @@ -334,12 +338,12 @@ plot_measures(
facet_var = measure,
title = "Number of consultations for each clinical condition by sex per month",
y_label = "Number of codes for consultations",
)
) + scale_color_manual(values = sex_palette)
```

### Breakdown by IMD

```{r, message=FALSE, warning=FALSE, fig.height=15, fig.width=8}
```{r, message=FALSE, warning=FALSE, fig.height=8, fig.width=8}
# Select measures and breakdown
df_measures_selected <- df_measures %>%
filter(measure_desc == "clinical_condition") %>%
Expand All @@ -356,12 +360,12 @@ plot_measures(
facet_var = measure,
title = "Number of consultations for each clinical condition by IMD per month",
y_label = "Number of codes for consultations",
)
) + scale_color_manual(values = gradient_palette)
```

### Breakdown by region

```{r, message=FALSE, warning=FALSE, fig.height=15, fig.width=8}
```{r, message=FALSE, warning=FALSE, fig.height=8, fig.width=8}
# Select measures and breakdown
df_measures_selected <- df_measures %>%
filter(measure_desc == "clinical_condition") %>%
Expand All @@ -378,12 +382,12 @@ plot_measures(
facet_var = measure,
title = "Number of consultations for each clinical condition by region per month",
y_label = "Number of codes for consultations",
)
) + scale_color_manual(values = region_palette)
```

### Clinical Conditions by ethnicity

```{r, message=FALSE, warning=FALSE, fig.height=15, fig.width=8}
```{r, message=FALSE, warning=FALSE, fig.height=8, fig.width=8}
# Select measures and breakdown
df_measures_selected <- df_measures %>%
filter(measure_desc == "clinical_condition") %>%
Expand All @@ -400,5 +404,5 @@ plot_measures(
facet_var = measure,
title = "Number of consultations for each clinical condition by ethnicity per month",
y_label = "Number of codes for consultations",
)
) + scale_color_manual(values = ethnicity_palette)
```