Skip to content
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

Move adjusted Fig 3 into appendix #117

Merged
merged 1 commit into from
Jan 31, 2025
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
2 changes: 1 addition & 1 deletion lib/functions/combine_os_nhsbsa_validation_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ df_os_validation_total <- bind_rows(
ungroup()

# Combine NHS BSA and OpenSAFELY data
pf_validation <- bind_rows(df_bsa_validation_total, df_os_validation_total)
pf_validation <- bind_rows(df_bsa_validation_total, df_os_validation_total)
153 changes: 130 additions & 23 deletions reports/create_results_manuscript.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fig_pf_grouped_consultations_count
ggsave(
filename = here("released_output", "results", "manuscript", "fig1_pf_consultation_count_total.png"),
fig_pf_grouped_consultations_count,
height = 4,
height = 3.5,
width = 8
)
```
Expand Down Expand Up @@ -180,6 +180,8 @@ fig_pf_med_condition_linkage <- ggplot(df_pf_descriptive_stats, aes(
text = element_text(size = 14)
)

fig_pf_med_condition_linkage

ggsave(
filename = here("released_output", "results", "manuscript", "fig2_pf_med_condition.png"),
fig_pf_med_condition_linkage,
Expand Down Expand Up @@ -217,6 +219,118 @@ df_results_pf_linkage %>%
# But this file uses datasets created further down so it easiest to load it here
source(here("lib", "functions", "combine_os_nhsbsa_validation_data.R"))

# Pharmacy First Consultations
# Instead of only using the count of PF consultations in OS with a clinical
# condition we are using all PF consultations with a consultation id
df_pf_consultation_validatio_plot <- pf_validation |>
filter(
(data_source == "opensafely" &
data_desc == "pf_consultation" &
count_desc == "consultation_id") |
(data_source == "nhs_bsa" &
data_desc == "pf_consultation" &
count_desc == "consultation_type")
)

# Pivot wider to calculate ratio
df_pf_consultation_validatio_plot <- df_pf_consultation_validatio_plot |>
select(date, data_source, count_method, count_total) |>
pivot_wider(names_from = c(data_source, count_method), values_from = count_total) |>
mutate(ratio = opensafely_opensafely_tpp / nhs_bsa_count_40pct)

# Select colours for groups
# Group 1: #CF4446FF
colour_group_1 <- paletteer_c("viridis::inferno", n = 10)[6]
# Group 1: #1B0C42FF
colour_group_2 <- paletteer_c("viridis::inferno", n = 10)[2]

# Create consultation validation plot
pf_validatio_consultation_plot <- df_pf_consultation_validatio_plot |>
ggplot(aes(x = date)) +
geom_point(
aes(
y = nhs_bsa_count_40pct,
colour = "NHS BSA (40%)",
shape = "NHS BSA (40%)"
),
size = 2.6
) +
geom_line(
aes(y = nhs_bsa_count_40pct, colour = "NHS BSA (40%)"),
alpha = .3,
size = .5
) +
geom_point(
aes(
y = opensafely_opensafely_tpp,
colour = "OpenSAFELY-TPP",
shape = "OpenSAFELY-TPP"
),
size = 2.6
) +
geom_line(
aes(
y = opensafely_opensafely_tpp,
colour = "OpenSAFELY-TPP"
),
alpha = .3,
size = .5
) +
geom_label(
aes(
y = opensafely_opensafely_tpp,
label = scales::percent(ratio, accuracy = .1),
),
colour = colour_group_2,
vjust = -.5,
size = 3.5
) +
scale_y_continuous(labels = scales::number) +
scale_x_date(
date_breaks = "1 month",
labels = scales::label_date_short()
) +
scale_colour_manual(
values = c(
"NHS BSA (40%)" = colour_group_1,
"OpenSAFELY-TPP" = colour_group_2
),
name = NULL
) +
scale_shape_manual(
values = c(
"NHS BSA (40%)" = 15,
"OpenSAFELY-TPP" = 16
),
name = NULL
) +
labs(
x = NULL,
y = NULL,
colour = NULL,
shape = NULL
) +
theme(
panel.background = element_blank(),
axis.line = element_line(colour = "grey50"),
legend.position = "bottom",
text = element_text(size = 14)
)

ggsave(
filename = here("released_output", "results", "manuscript", "fig3_pf_os_nhsbsa_comparison.png"),
pf_validatio_consultation_plot,
height = 4,
width = 8
)
```
# Appendix

## Data comparison adjusted for % linkage

### Consultation

```{r, message=FALSE, warning=FALSE, echo = FALSE}
# Pharmacy First Consultations
# Instead of only using the count of PF consultations in OS with a clinical
# condition we are using all PF consultations with a consultation id
Expand Down Expand Up @@ -244,7 +358,7 @@ join_ratio <- df_pf_descriptive_stats |>
ungroup() |>
select(date, ratio_consultation_type_in_os)

df_pf_consultation_validation_plot <- df_pf_consultation_validation_plot |>
df_pf_consultation_validation_adjusted_plot <- df_pf_consultation_validation_plot |>
left_join(join_ratio) |>
mutate(
os_tpp_adjusted = round((opensafely_opensafely_tpp / (ratio_consultation_type_in_os * 100)) * 100, 0),
Expand All @@ -260,7 +374,7 @@ colour_group_2 <- paletteer_c("viridis::inferno", n = 10)[2]
colour_group_3 <- paletteer_c("viridis::inferno", n = 10)[4]

# Create consultation validation plot
pf_validation_consultation_plot <- df_pf_consultation_validation_plot |>
pf_validation_consultation_adjusted_plot <- df_pf_consultation_validation_adjusted_plot |>
ggplot(aes(x = date)) +
geom_point(
aes(
Expand Down Expand Up @@ -342,7 +456,7 @@ pf_validation_consultation_plot <- df_pf_consultation_validation_plot |>
values = c(
"NHS BSA (40%)" = 15,
"OpenSAFELY-TPP" = 16,
"OpenSAFELY-TPP (Adjusted)" = 16
"OpenSAFELY-TPP (Adjusted)" = 17
),
name = NULL
) +
Expand All @@ -359,15 +473,10 @@ pf_validation_consultation_plot <- df_pf_consultation_validation_plot |>
text = element_text(size = 14)
) +
ggtitle("A. Pharmacy First Consultations")

ggsave(
filename = here("released_output", "results", "manuscript", "fig3_pf_os_nhsbsa_comparison.png"),
pf_validation_consultation_plot,
height = 4,
width = 8
)
```

### Medications

```{r, message=FALSE, warning=FALSE, echo = FALSE}
df_pf_medication_validation <- pf_validation |>
filter(
Expand All @@ -393,15 +502,15 @@ linked_ratio <- df_pf_descriptive_stats |>
select(date, ratio_medication_in_os)


df_pf_medication_validation_plot <- df_pf_medication_validation_plot |>
df_pf_medication_validation_adjusted_plot <- df_pf_medication_validation_plot |>
left_join(linked_ratio) |>
mutate(
os_tpp_adjusted = round((opensafely_opensafely_tpp / (ratio_medication_in_os * 100)) * 100, 0),
ratio_adjusted = os_tpp_adjusted / nhs_bsa_count_40pct
)

# Create consultation validation plot
pf_medication_validation_plot <- df_pf_medication_validation_plot |>
pf_medication_validation_adjusted_plot <- df_pf_medication_validation_adjusted_plot |>
ggplot(aes(x = date)) +
geom_point(
aes(
Expand Down Expand Up @@ -483,7 +592,7 @@ pf_medication_validation_plot <- df_pf_medication_validation_plot |>
values = c(
"NHS BSA (40%)" = 15,
"OpenSAFELY-TPP" = 16,
"OpenSAFELY-TPP (Adjusted)" = 16
"OpenSAFELY-TPP (Adjusted)" = 17
),
name = NULL
) +
Expand All @@ -500,19 +609,17 @@ pf_medication_validation_plot <- df_pf_medication_validation_plot |>
text = element_text(size = 14)
) +
ggtitle("B. Pharmacy First Medications")
```

ggsave(
filename = here("released_output", "results", "manuscript", "fig3_pfmed_os_nhsbsa_comparison.png"),
pf_medication_validation_plot,
height = 4,
width = 8
)
```{r}
# Combine plots
validation_combined_adjusted_plot <- pf_validation_consultation_adjusted_plot / pf_medication_validation_adjusted_plot + plot_layout(guides = "collect") & theme(legend.position = "bottom")

validation_combined_plot <- pf_validation_consultation_plot / pf_medication_validation_plot + plot_layout(guides = "collect") & theme(legend.position = "bottom")
validation_combined_adjusted_plot

ggsave(
filename = here("released_output", "results", "manuscript", "fig3_pf_combined_os_nhsbsa_comparison.png"),
validation_combined_plot,
filename = here("released_output", "results", "manuscript", "figX_pf_os_nhsbsa_adjusted_comparison.png"),
validation_combined_adjusted_plot,
height = 8,
width = 10
)
Expand Down