-
Notifications
You must be signed in to change notification settings - Fork 22
/
README.Rmd
204 lines (157 loc) · 6.63 KB
/
README.Rmd
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
dev.args = list(png = list(type = "cairo")),
fig.retina = 3
)
```
# NHSRplotthedots <a alt="NHS-R Community's logo" href='https://nhsrcommunity.com/'><img src='https://nhs-r-community.github.io/assets/logo/nhsr-logo.png' align="right" height="80" /></a>
<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R-CMD-check](https://github.com/nhs-r-community/NHSRplotthedots/workflows/R-CMD-check/badge.svg)](https://github.com/nhs-r-community/NHSRplotthedots/actions)
[![Codecov test coverage](https://codecov.io/gh/nhs-r-community/NHSRplotthedots/branch/main/graph/badge.svg)](https://app.codecov.io/gh/nhs-r-community/NHSRplotthedots?branch=main)
[![CRAN status](https://www.r-pkg.org/badges/version/NHSRplotthedots)](https://CRAN.R-project.org/package=NHSRplotthedots)
[![downloads](https://cranlogs.r-pkg.org/badges/grand-total/NHSRplotthedots)](https://CRAN.R-project.org/package=NHSRplotthedots)
<!-- badges: end -->
This package is built by the [NHS-R community][nhsr] to provide tools for drawing statistical process control (SPC)
charts. This package supports NHS England's ['Making Data Count'][mdc] programme, and allows users to draw XmR charts,
use change points, and apply rules with summary indicators for when rules are breached.
Please be aware that this package is in the early stages of development, and features may change.
## Installation
```r
# install from CRAN
install.packages("NHSRplotthedots")
# Or install the development version from GitHub using {remotes} package:
# install.packages("remotes")
remotes::install_github("https://github.com/nhs-r-community/NHSRplotthedots", build_vignettes = TRUE)
```
# Overview
Welcome to the NHS-R community's package for building a specific type of statistical process control (SPC) chart, the XmR chart.
We are aiming to support NHS England's ['Making Data Count'][mdc] programme.
The programme encourages boards, managers, and analyst teams to present data in ways that show change over time and drive better understanding of indicators than 'RAG' (red, amber, green) rated board reports often present.
The help files and vignettes within this package tell you more about the possible options for controlling the charts, but below are some simple examples of the type of chart the package produces.
We will use the `ae_attendances` dataset from the `{NHSRdatasets}` package and a bit of `{dplyr}` code to select some organisations.
```{r example1, message=FALSE, warning=FALSE}
library(NHSRplotthedots)
library(NHSRdatasets)
library(dplyr)
sub_set <- ae_attendances |>
filter(org_code == "RQM", type == 1, period < as.Date("2018-04-01"))
sub_set |>
ptd_spc(
value_field = breaches,
date_field = period,
improvement_direction = "decrease"
)
```
This plot is ok on its own, but we can specify more control options if we explicitly pass it on to the `plot()` function.
```{r example2}
sub_set |>
ptd_spc(
value_field = breaches,
date_field = period,
improvement_direction = "decrease"
) |>
plot(
y_axis_label = "4-hour wait breaches",
main_title = "SPC of A&E waiting time breaches for RQM"
)
```
or, equivalently:
```r
sub_set |>
ptd_spc(
value_field = breaches,
date_field = period,
improvement_direction = "decrease"
) |>
ptd_create_ggplot(
y_axis_label = "4-hour wait breaches",
main_title = "SPC of A&E waiting time breaches for RQM"
)
```
You can also use the `summary()` function to get some basic statistics about your SPC data frame.
The function prints the SPC options, and then returns the summarised results as a table:
```{r summary-example}
summary <- sub_set |>
ptd_spc(
value_field = breaches,
date_field = period,
improvement_direction = "decrease",
target = 1200
) |>
summary()
```
You could assign this summary table to a variable and use it later:
```{r}
summary$variation_type
summary$assurance_type
```
### Interactive plots with Plotly
It's also possible to generate interactive plots using the `{plotly}` package by replacing the call to `plot` with `ptd_create_plotly`.
This function takes the same arguments as `plot`/`ptd_create_ggplot`.
```r
sub_set |>
ptd_spc(
value_field = breaches,
date_field = period,
improvement_direction = "decrease"
) |>
ptd_create_plotly(
y_axis_label = "4-hour wait breaches",
main_title = "SPC of A&E waiting time breaches for RQM"
)
```
### Adding annotations for mean and process limits
The package (from v0.2.0) supports annotating the values of the mean and the
upper and lower process limits on a secondary (right-hand side) y axis,
if this is helpful for you and your audience.
The way to achieve this is to turn on the `label_limits` option:
```{r limits-example}
sub_set |>
ptd_spc(
value_field = breaches,
date_field = period,
improvement_direction = "decrease"
) |>
ptd_create_ggplot(
y_axis_label = "4-hour wait breaches",
main_title = "SPC of A&E waiting time breaches for RQM",
label_limits = TRUE
)
```
If you have rebased the chart, the mean and process limit annotations will only show for the most recent section.
## Getting help
To find out more about the `ptd_spc()` function, you can view the help with:
```r
?ptd_spc
```
Details on the extra plot controls can be found using:
```r
?ptd_create_ggplot
```
To view the vignette (worked example), use:
```r
vignette("intro", package = "NHSRplotthedots")
vignette(package = "NHSRplotthedots")
```
# Contributing
This is an NHS-R Community project that is open for anyone to contribute to in any way that they are able.
The project is released with a [Contributor Code of Conduct][coc].
By contributing to this project, you agree to abide by its terms.
If you want to learn more about this project, please join the discussion at
[the NHS-R Community Slack group][nhsr-slack] and the specific channel
[#proj-nhsr-plot-the-dots][ptd-slack-channel].
The simplest way to contribute is to raise an issue detailing the feature or functionality you would like to see added, or any unexpected behaviour or bugs you have experienced.
[nhsr]: https://nhsrcommunity.com
[mdc]: https://www.england.nhs.uk/publication/making-data-count/
[coc]: https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html
[nhsr-slack]: https://nhsrcommunity.slack.com/
[ptd-slack-channel]: https://nhsrcommunity.slack.com/archives/CSVD4SYF3