Interactively selecting indicators

Seb Fox

2017-09-27

This short example introduces two new features included in the 0.1.1 version of the package:

The following libraries are needed for this vignette:

library(fingertipsR)
library(ggplot2)

To begin with, we want to select the indicators that we want to analyse in this example. The select_indicators() function helps us do this:

inds <- select_indicators()

After running the above code a browser window opens and will spend some time loading while it accesses the available indicators. Once loaded, the search bar in the top right corner allows the user to type in any searches to help locate the indicators of interest. This example will use the following indicators, selected at random, which belong to the Public Health Outcomes Framework profile. Note, the indicator IDs of the selected indicators are displayed on the left-hand side. The user can click an indicator for a second time to deselect the indicator if it has been selected unnecessarily.

##  [1] 90630 10101 10301 92313 10401 11401 10501 92314 11502 10601 20101
## [12] 20201 20601 20301 20602 90284 90832 90285 22001 22002 90244

The second function to be highlighted in this vignette is fingertips_redred(). This will return a data frame of the data for all of the areas that are performing significantly worse than the chosen benchmark and are deteriorating.

df <- fingertips_redred(inds, Comparator = "England")
## Warning in rbind(names(probs), probs_f): number of columns of result is not
## a multiple of vector length (arg 1)
## Warning: 4 parsing failures.
## row # A tibble: 4 x 5 col     row         col   expected     actual         file expected   <int>       <chr>      <chr>      <chr>        <chr> actual 1   437 Denominator an integer 2282241295 <raw vector> file 2   647 Denominator an integer 2308294152 <raw vector> row 3   857 Denominator an integer 2358381053 <raw vector> col 4  1068 Denominator an integer 2398192098 <raw vector>
## Warning in rbind(names(probs), probs_f): number of columns of result is not
## a multiple of vector length (arg 1)
## Warning: 359 parsing failures.
## row # A tibble: 5 x 5 col     row         col               expected     actual         file expected   <int>       <chr>                  <chr>      <chr>        <chr> actual 1     3 Denominator no trailing characters .666666667 <raw vector> file 2     5 Denominator no trailing characters .666666667 <raw vector> row 3     6 Denominator no trailing characters .666666667 <raw vector> col 4     8 Denominator no trailing characters .333333333 <raw vector> expected 5     9 Denominator no trailing characters .333333333 <raw vector>
## ... ................. ... .................................................................. ........ .................................................................. ...... .................................................................. .... .................................................................. ... .................................................................. ... .................................................................. ........ ..................................................................
## See problems(...) for more details.
## Warning in rbind(names(probs), probs_f): number of columns of result is not
## a multiple of vector length (arg 1)
## Warning: 198 parsing failures.
## row # A tibble: 5 x 5 col     row         col               expected actual         file expected   <int>       <chr>                  <chr>  <chr>        <chr> actual 1   607 Denominator no trailing characters   .903 <raw vector> file 2   608 Denominator no trailing characters   .256 <raw vector> row 3   609 Denominator no trailing characters   .765 <raw vector> col 4   610 Denominator no trailing characters   .077 <raw vector> expected 5   611 Denominator no trailing characters   .349 <raw vector>
## ... ................. ... .............................................................. ........ .............................................................. ...... .............................................................. .... .............................................................. ... .............................................................. ... .............................................................. ........ ..............................................................
## See problems(...) for more details.
## Warning in rbind(names(probs), probs_f): number of columns of result is not
## a multiple of vector length (arg 1)
## Warning: 199 parsing failures.
## row # A tibble: 5 x 5 col     row         col               expected      actual         file expected   <int>       <chr>                  <chr>       <chr>        <chr> actual 1    12 Denominator no trailing characters  .126064021 <raw vector> file 2    13 Denominator no trailing characters .8355684944 <raw vector> row 3    14 Denominator no trailing characters .6907266548 <raw vector> col 4    15 Denominator no trailing characters .0689849006 <raw vector> expected 5    16 Denominator no trailing characters .9433052298 <raw vector>
## ... ................. ... ................................................................... ........ ................................................................... ...... ................................................................... .... ................................................................... ... ................................................................... ... ................................................................... ........ ...................................................................
## See problems(...) for more details.
## Warning in rbind(names(probs), probs_f): number of columns of result is not
## a multiple of vector length (arg 1)
## Warning: 492 parsing failures.
## row # A tibble: 5 x 5 col     row         col               expected      actual         file expected   <int>       <chr>                  <chr>       <chr>        <chr> actual 1    12 Denominator no trailing characters  .126064021 <raw vector> file 2    13 Denominator no trailing characters .8355684944 <raw vector> row 3    14 Denominator no trailing characters .6907266548 <raw vector> col 4    15 Denominator no trailing characters .0689849006 <raw vector> expected 5    16 Denominator no trailing characters .9433052298 <raw vector>
## ... ................. ... ................................................................... ........ ................................................................... ...... ................................................................... .... ................................................................... ... ................................................................... ... ................................................................... ........ ...................................................................
## See problems(...) for more details.
## Warning in rbind(names(probs), probs_f): number of columns of result is not
## a multiple of vector length (arg 1)
## Warning: 30 parsing failures.
## row # A tibble: 5 x 5 col     row         col               expected          actual         file expected   <int>       <chr>                  <chr>           <chr>        <chr> actual 1     2 Denominator no trailing characters .97499957592856 <raw vector> file 2     3 Denominator no trailing characters .75394498188557 <raw vector> row 3     4 Denominator no trailing characters  .6253670482037 <raw vector> col 4     5 Denominator no trailing characters .81601491566345 <raw vector> expected 5     6 Denominator no trailing characters .50777105177773 <raw vector>
## ... ................. ... ....................................................................... ........ ....................................................................... ...... ....................................................................... .... ....................................................................... ... ....................................................................... ... ....................................................................... ........ .......................................................................
## See problems(...) for more details.

The geom_tile() function from ggplot2 can be used to visualise the poorly performing areas:

df$IndicatorName <- sapply(strwrap(df$IndicatorName, 60, 
                                   simplify = FALSE), 
                           paste, collapse= "\n")
p <- ggplot(df, aes(IndicatorName, AreaName)) + 
        geom_tile(fill = "darkred",
                  colour = "white") + 
        theme_minimal() +
        theme(axis.text.x = element_text(angle = 45,
                                         hjust = 1,
                                         size = rel(0.85)),
              axis.text.y = element_text(size = rel(0.9))) +
        labs(y = "Upper Tier Local Authority",
             x = "Indicator")
print(p)