Skip to content

Commit

Permalink
Add Hex Sticker
Browse files Browse the repository at this point in the history
  • Loading branch information
3styleJam committed Jan 31, 2025
1 parent e74d1f3 commit 4f58951
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 87 deletions.
22 changes: 21 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ knitr::opts_chunk$set(
)
```

# 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>
:::: {style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;"}

::: {style="flex: 1 1 50%;"}

# NHSRplotthedots

<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
Expand All @@ -25,6 +29,22 @@ knitr::opts_chunk$set(
[![downloads](https://cranlogs.r-pkg.org/badges/grand-total/NHSRplotthedots)](https://CRAN.R-project.org/package=NHSRplotthedots)
<!-- badges: end -->

:::

::: {style="flex: 1 1 auto;"}

<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="center" height="80"/></a>

:::

::: {style="flex: 1 1 auto;"}

<img src="inst/images/logo.png" align="center" height="160"/>

:::

::::

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.
Expand Down
221 changes: 135 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# 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>
<div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;">

<div style="flex: 1 1 50%;">

# NHSRplotthedots

<!-- badges: start -->

Expand All @@ -14,6 +19,22 @@ status](https://www.r-pkg.org/badges/version/NHSRplotthedots)](https://CRAN.R-pr
[![downloads](https://cranlogs.r-pkg.org/badges/grand-total/NHSRplotthedots)](https://CRAN.R-project.org/package=NHSRplotthedots)
<!-- badges: end -->

</div>

<div style="flex: 1 1 auto;">

<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="center" height="80"/></a>

</div>

<div style="flex: 1 1 auto;">

<img src="inst/images/logo.png" align="center" height="160"/>

</div>

</div>

This package is built by the [NHS-R
community](https://nhsrcommunity.com) to provide tools for drawing
statistical process control (SPC) charts. This package supports NHS
Expand All @@ -27,12 +48,14 @@ and features may change.

## Installation

# install from CRAN
install.packages("NHSRplotthedots")
``` 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)
# 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

Expand All @@ -51,99 +74,115 @@ 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.

library(NHSRplotthedots)
library(NHSRdatasets)
library(dplyr)
``` r
library(NHSRplotthedots)
library(NHSRdatasets)
library(dplyr)

sub_set <- ae_attendances |>
filter(org_code == "RQM", type == 1, period < as.Date("2018-04-01"))
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"
)
sub_set |>
ptd_spc(
value_field = breaches,
date_field = period,
improvement_direction = "decrease"
)
```

<img src="man/figures/README-example1-1.png" width="100%" />

This plot is ok on its own, but we can specify more control options if
we explicitly pass it on to the `plot()` function.

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"
)
``` r
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"
)
```

<img src="man/figures/README-example2-1.png" width="100%" />

or, equivalently:

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"
)
``` 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:

summary <- sub_set |>
ptd_spc(
value_field = breaches,
date_field = period,
improvement_direction = "decrease",
target = 1200
) |>
summary()
#> Plot the Dots SPC options:
#> ================================
#> value_field: 'breaches'
#> date_field: 'period'
#> facet_field: not set
#> rebase: not set
#> fix_after_n_points: not set
#> improvement_direction:'decrease'
#> target: '1200'
#> trajectory: not set
#> screen_outliers: 'TRUE'
#> --------------------------------
``` r
summary <- sub_set |>
ptd_spc(
value_field = breaches,
date_field = period,
improvement_direction = "decrease",
target = 1200
) |>
summary()
#> Plot the Dots SPC options:
#> ================================
#> value_field: 'breaches'
#> date_field: 'period'
#> facet_field: not set
#> rebase: not set
#> fix_after_n_points: not set
#> improvement_direction:'decrease'
#> target: '1200'
#> trajectory: not set
#> screen_outliers: 'TRUE'
#> --------------------------------
```

You could assign this summary table to a variable and use it later:

summary$variation_type
#> [1] "common_cause"
summary$assurance_type
#> [1] "inconsistent"
``` r
summary$variation_type
#> Warning: Unknown or uninitialised column: `variation_type`.
#> NULL
```

``` r
summary$assurance_type
#> [1] "inconsistent"
```

### 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`.

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"
)
``` 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

Expand All @@ -153,17 +192,21 @@ axis, if this is helpful for you and your audience.

The way to achieve this is to turn on the `label_limits` option:

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
)
``` 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",
label_limits = TRUE
)
#> Warning in ptd_create_ggplot(ptd_spc(sub_set, value_field = breaches, date_field = period, : Unknown arguments provided by plot: label_limits
#> Check for common spelling mistakes in arguments.
```

<img src="man/figures/README-limits-example-1.png" width="100%" />

Expand All @@ -175,17 +218,23 @@ will only show for the most recent section.
To find out more about the `ptd_spc()` function, you can view the help
with:

?ptd_spc
``` r
?ptd_spc
```

Details on the extra plot controls can be found using:

?ptd_create_ggplot
``` r
?ptd_create_ggplot
```

To view the vignette (worked example), use:

vignette("intro", package = "NHSRplotthedots")
``` r
vignette("intro", package = "NHSRplotthedots")

vignette(package = "NHSRplotthedots")
vignette(package = "NHSRplotthedots")
```

# Contributing

Expand Down
Binary file modified man/figures/README-example1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-example2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-limits-example-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4f58951

Please sign in to comment.