generated from opensafely/research-template
/
summary_plots.R
150 lines (127 loc) · 5.63 KB
/
summary_plots.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
######################################
# This script:
# - imports data
# - saves data summaries (tables and figures)
######################################
# Preliminaries ----
## Import libraries
library('tidyverse')
library('lubridate')
library('reshape2')
library('here')
## Create output directory
dir.create(here::here("output", "figures"), showWarnings = FALSE, recursive=TRUE)
## Import processed data
data_processed <- readRDS(here::here("output", "data", "data_processed_totals.rds"))
# Figures ----
## Total number of antipsychotics issued
### First generation antipsychotics, excluding long acting depots
antipsychotics_first_gen <- ggplot(data_processed, aes(x = date, y = antipsychotics_first_gen, colour = group)) +
geom_line() +
facet_wrap(~group, scales = "free") +
theme_bw() +
theme(legend.position = "none") +
ylab("Total number of first generation antipsychotics (excluding long acting depots) issued per month") +
xlab("date") +
scale_x_date(date_breaks = "3 month", date_labels = "%b %Y") +
theme(axis.text.x = element_text(angle = 60, hjust = 1))
ggsave(filename=here::here("output", "figures", "plot_total_antipsychotics_first_gen.svg"),
antipsychotics_first_gen,
units = "cm", width = 40, height = 20
)
### Second generation antipsychotics, excluding long acting depots
antipsychotics_second_gen <- ggplot(data_processed, aes(x = date, y = antipsychotics_second_gen, colour = group)) +
geom_line() +
facet_wrap(~group, scales = "free") +
theme_bw() +
theme(legend.position = "none") +
ylab("Total number of second generation antipsychotics (excluding long acting depots) issued per month") +
xlab("date") +
scale_x_date(date_breaks = "3 month", date_labels = "%b %Y") +
theme(axis.text.x = element_text(angle = 60, hjust = 1))
ggsave(filename=here::here("output", "figures", "plot_total_antipsychotics_second_gen.svg"),
antipsychotics_second_gen,
units = "cm", width = 40, height = 20
)
### Long acting injectable and depot antipsychotics
antipsychotics_injectable_and_depot <- ggplot(data_processed, aes(x = date, y = antipsychotics_injectable_and_depot, colour = group)) +
geom_line() +
facet_wrap(~group, scales = "free") +
theme_bw() +
theme(legend.position = "none") +
ylab("Total number of injectable and depot antipsychotics issued per month") +
xlab("date") +
scale_x_date(date_breaks = "3 month", date_labels = "%b %Y") +
theme(axis.text.x = element_text(angle = 60, hjust = 1))
ggsave(filename=here::here("output", "figures", "plot_total_antipsychotics_injectable_and_depot.svg"),
antipsychotics_injectable_and_depot,
units = "cm", width = 40, height = 20
)
### Prochlorperazine
prochlorperazine <- ggplot(data_processed, aes(x = date, y = prochlorperazine, colour = group)) +
geom_line() +
facet_wrap(~group, scales = "free") +
theme_bw() +
theme(legend.position = "none") +
ylab("Absolute number of prochlorperazine antipsychotics issued per month") +
xlab("date") +
scale_x_date(date_breaks = "3 month", date_labels = "%b %Y") +
theme(axis.text.x = element_text(angle = 60, hjust = 1))
ggsave(filename=here::here("output", "figures", "plot_total_prochlorperazine.svg"),
prochlorperazine,
units = "cm", width = 40, height = 20
)
# ## Learning disability inequalities
#
# ### Sex
# data_ld_by_sex <- data_processed_learning_disability %>%
# select(date, antipsychotics_first_gen, antipsychotics_second_gen, antipsychotics_injectable_and_depot, prochlorperazine,
# sex) %>%
# group_by(date, sex) %>%
# summarise(antipsychotics_first_gen = sum(antipsychotics_first_gen, na.rm = T),
# antipsychotics_second_gen = sum(antipsychotics_second_gen, na.rm = T),
# antipsychotics_injectable_and_depot = sum(antipsychotics_injectable_and_depot, na.rm = T),
# prochlorperazine = sum(prochlorperazine, na.rm = T)) %>%
# melt(id.vars = c("date", "sex")) %>%
# ggplot(aes(x = date, y = value, colour = sex)) +
# geom_line() +
# facet_wrap(~variable, scales = "free") +
# theme_bw() +
# theme(legend.position = "bottom") +
# ylab("Absolute number of antipsychotics issued to those with learning disabilities per month, by sex") +
# xlab("date") +
# scale_x_date(date_breaks = "3 month", date_labels = "%b %Y") +
# theme(axis.text.x = element_text(angle = 60, hjust = 1))
#
# ggsave(
# here::here("output", "figures", "plot_ld_sex.svg"),
# data_ld_by_sex,
# units = "cm", width = 40, height = 20
# )
#
# ### IMD
# data_ld_by_imd <- data_processed_learning_disability %>%
# select(date, antipsychotics_first_gen, antipsychotics_second_gen, antipsychotics_injectable_and_depot, prochlorperazine,
# imd) %>%
# filter(imd != 0) %>%
# group_by(date, imd) %>%
# summarise(antipsychotics_first_gen = sum(antipsychotics_first_gen, na.rm = T),
# antipsychotics_second_gen = sum(antipsychotics_second_gen, na.rm = T),
# antipsychotics_injectable_and_depot = sum(antipsychotics_injectable_and_depot, na.rm = T),
# prochlorperazine = sum(prochlorperazine, na.rm = T)) %>%
# melt(id.vars = c("date", "imd")) %>%
# ggplot(aes(x = date, y = value, colour = imd)) +
# geom_line() +
# facet_wrap(~variable, scales = "free") +
# theme_bw() +
# theme(legend.position = "bottom") +
# ylab("Absolute number of antipsychotics issued to those with learning disabilities per month, by imd") +
# xlab("date") +
# scale_x_date(date_breaks = "3 month", date_labels = "%b %Y") +
# theme(axis.text.x = element_text(angle = 60, hjust = 1))
#
# ggsave(
# here::here("output", "figures", "plot_ld_imd.svg"),
# data_ld_by_imd,
# units = "cm", width = 40, height = 20
# )