SIMD by Local Authorities

#Introduction

Code used to create the plot in a “Data insights” brief on the Scottish Centre for Adminsitrative Data Research website found here (insert link here)

The post shows a plot I used in my PhD thesis which shows the distribution of the over-65 population in Scotland by SIMD decile. Check out the insights document for a bit more info. This post is really just for code.

#Make the plot

##Load packages

library(tidyverse)
library(ggthemes)
library(extrafont)
library(kableExtra)
library(here)
here()
## [1] "C:/GitHub/davidhen_web"
#set plot theme and colour palette
theme_set(theme_minimal(base_size = 20, base_family = "Calibri Light"))
scadr_colours <- c("#011e41", "#160b75", "#330072", "#009658", "#007d8a", 
                   "#09db9b", "#67899C", "#9896d9", "#a7aca2", "#f7a700")

##Load data

I’ve saved the table used to make the data my website folder. If you want a copy then give me a shout.

la_table <- read_csv("2019-11-29_scadr_brief_code/la_data.csv")
## Parsed with column specification:
## cols(
##   X1 = col_double(),
##   council = col_character(),
##   simd = col_double(),
##   n = col_double(),
##   frq = col_double()
## )

##Show the table

A quick look to see what we will be plotting

la_table
## # A tibble: 296 x 5
##       X1 council        simd     n   frq
##    <dbl> <chr>         <dbl> <dbl> <dbl>
##  1     1 Aberdeen City     1   192 0.006
##  2     2 Aberdeen City     2  2069 0.062
##  3     3 Aberdeen City     3  3545 0.107
##  4     4 Aberdeen City     4  3567 0.107
##  5     5 Aberdeen City     5  2802 0.084
##  6     6 Aberdeen City     6  2456 0.074
##  7     7 Aberdeen City     7  2635 0.079
##  8     8 Aberdeen City     8  2754 0.083
##  9     9 Aberdeen City     9  3801 0.114
## 10    10 Aberdeen City    10  9397 0.283
## # ... with 286 more rows

##…and now plot the data

la_table %>% 
  #need to factorise simd
  ggplot(aes(factor(simd), frq, fill = factor(simd))) +
  geom_col() +
  #add maual colouring
  scale_fill_manual(values = scadr_colours,
                    guide = guide_legend(nrow = 1),
                    labels = c("1-most deprived", "2", "3", "4", "5",
                             "6", "7", "8", "9", "10-most affluent")) +
  #adjust y-axis scales
  scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
  #add the small multiples
  facet_wrap(~council, strip.position = "bottom") +
  #aesthetic changes to text
  theme(legend.position = "bottom",
        legend.text = element_text(colour = alpha("#011e41", 0.7)),
        axis.text.x = element_blank(),
        plot.title = element_text(colour = "#007d8a"),
        plot.subtitle = element_text(colour = alpha("#011e41", 0.7)),
        axis.text = element_text(colour = alpha("#011e41", 0.7)),
        strip.text = element_text(colour = alpha("#011e41", 0.7)),
        plot.caption = element_text(size = 14, 
                                    colour = alpha("#011e41", 0.7))) +
  #Add the labels
  labs(title = "Percentage of over 65s in SIMD deciles",
       subtitle = "by Local Authority (2015/16)",
       caption = "Clackmannanshire not included",
       x = "",
       y = "",
       fill = "SIMD decile") -> simd_la
simd_la

#Session information

devtools::session_info()
## - Session info ---------------------------------------------------------------
##  setting  value                       
##  version  R version 3.6.1 (2019-07-05)
##  os       Windows 10 x64              
##  system   x86_64, mingw32             
##  ui       RTerm                       
##  language (EN)                        
##  collate  English_United Kingdom.1252 
##  ctype    English_United Kingdom.1252 
##  tz       Europe/London               
##  date     2019-12-05                  
## 
## - Packages -------------------------------------------------------------------
##  package     * version date       lib source        
##  assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.5.3)
##  backports     1.1.5   2019-10-02 [1] CRAN (R 3.6.1)
##  blogdown      0.17    2019-11-13 [1] CRAN (R 3.6.1)
##  bookdown      0.16    2019-11-22 [1] CRAN (R 3.6.1)
##  broom         0.5.2   2019-04-07 [1] CRAN (R 3.5.3)
##  callr         3.3.2   2019-09-22 [1] CRAN (R 3.6.1)
##  cellranger    1.1.0   2016-07-27 [1] CRAN (R 3.5.1)
##  cli           1.1.0   2019-03-19 [1] CRAN (R 3.5.3)
##  colorspace    1.4-1   2019-03-18 [1] CRAN (R 3.5.3)
##  crayon        1.3.4   2017-09-16 [1] CRAN (R 3.5.1)
##  DBI           1.0.0   2018-05-02 [1] CRAN (R 3.5.1)
##  dbplyr        1.4.2   2019-06-17 [1] CRAN (R 3.5.3)
##  desc          1.2.0   2018-05-01 [1] CRAN (R 3.5.1)
##  devtools      2.2.1   2019-09-24 [1] CRAN (R 3.6.1)
##  digest        0.6.23  2019-11-23 [1] CRAN (R 3.6.1)
##  dplyr       * 0.8.3   2019-07-04 [1] CRAN (R 3.6.1)
##  ellipsis      0.3.0   2019-09-20 [1] CRAN (R 3.6.1)
##  evaluate      0.14    2019-05-28 [1] CRAN (R 3.5.3)
##  extrafont   * 0.17    2014-12-08 [1] CRAN (R 3.5.0)
##  extrafontdb   1.0     2012-06-11 [1] CRAN (R 3.5.0)
##  fansi         0.4.0   2018-10-05 [1] CRAN (R 3.5.1)
##  farver        2.0.1   2019-11-13 [1] CRAN (R 3.6.1)
##  forcats     * 0.4.0   2019-02-17 [1] CRAN (R 3.5.2)
##  fs            1.3.1   2019-05-06 [1] CRAN (R 3.5.3)
##  generics      0.0.2   2018-11-29 [1] CRAN (R 3.5.2)
##  ggplot2     * 3.2.1   2019-08-10 [1] CRAN (R 3.6.1)
##  ggthemes    * 4.2.0   2019-05-13 [1] CRAN (R 3.5.3)
##  glue          1.3.1   2019-03-12 [1] CRAN (R 3.5.3)
##  gtable        0.3.0   2019-03-25 [1] CRAN (R 3.5.3)
##  haven         2.2.0   2019-11-08 [1] CRAN (R 3.6.1)
##  here        * 0.1     2017-05-28 [1] CRAN (R 3.5.1)
##  hms           0.5.2   2019-10-30 [1] CRAN (R 3.6.1)
##  htmltools     0.4.0   2019-10-04 [1] CRAN (R 3.6.1)
##  httr          1.4.1   2019-08-05 [1] CRAN (R 3.6.1)
##  jsonlite      1.6     2018-12-07 [1] CRAN (R 3.5.2)
##  kableExtra  * 1.1.0   2019-03-16 [1] CRAN (R 3.5.3)
##  knitr         1.26    2019-11-12 [1] CRAN (R 3.6.1)
##  labeling      0.3     2014-08-23 [1] CRAN (R 3.5.0)
##  lattice       0.20-38 2018-11-04 [1] CRAN (R 3.6.1)
##  lazyeval      0.2.2   2019-03-15 [1] CRAN (R 3.5.3)
##  lifecycle     0.1.0   2019-08-01 [1] CRAN (R 3.6.1)
##  lubridate     1.7.4   2018-04-11 [1] CRAN (R 3.5.1)
##  magrittr      1.5     2014-11-22 [1] CRAN (R 3.5.1)
##  memoise       1.1.0   2017-04-21 [1] CRAN (R 3.5.1)
##  modelr        0.1.5   2019-08-08 [1] CRAN (R 3.6.1)
##  munsell       0.5.0   2018-06-12 [1] CRAN (R 3.5.1)
##  nlme          3.1-142 2019-11-07 [1] CRAN (R 3.6.1)
##  pillar        1.4.2   2019-06-29 [1] CRAN (R 3.6.1)
##  pkgbuild      1.0.6   2019-10-09 [1] CRAN (R 3.6.0)
##  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 3.6.1)
##  pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.5.1)
##  prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.5.1)
##  processx      3.4.1   2019-07-18 [1] CRAN (R 3.6.1)
##  ps            1.3.0   2018-12-21 [1] CRAN (R 3.5.2)
##  purrr       * 0.3.3   2019-10-18 [1] CRAN (R 3.6.1)
##  R6            2.4.1   2019-11-12 [1] CRAN (R 3.6.1)
##  Rcpp          1.0.3   2019-11-08 [1] CRAN (R 3.6.1)
##  readr       * 1.3.1   2018-12-21 [1] CRAN (R 3.5.2)
##  readxl        1.3.1   2019-03-13 [1] CRAN (R 3.5.3)
##  remotes       2.1.0   2019-06-24 [1] CRAN (R 3.6.1)
##  reprex        0.3.0   2019-05-16 [1] CRAN (R 3.5.3)
##  rlang         0.4.2   2019-11-23 [1] CRAN (R 3.6.1)
##  rmarkdown     1.17    2019-11-13 [1] CRAN (R 3.6.1)
##  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.5.1)
##  rstudioapi    0.10    2019-03-19 [1] CRAN (R 3.5.3)
##  Rttf2pt1      1.3.7   2018-06-29 [1] CRAN (R 3.5.0)
##  rvest         0.3.5   2019-11-08 [1] CRAN (R 3.6.1)
##  scales        1.1.0   2019-11-18 [1] CRAN (R 3.6.1)
##  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.5.1)
##  stringi       1.4.3   2019-03-12 [1] CRAN (R 3.5.3)
##  stringr     * 1.4.0   2019-02-10 [1] CRAN (R 3.5.2)
##  testthat      2.3.0   2019-11-05 [1] CRAN (R 3.6.1)
##  tibble      * 2.1.3   2019-06-06 [1] CRAN (R 3.6.1)
##  tidyr       * 1.0.0   2019-09-11 [1] CRAN (R 3.6.1)
##  tidyselect    0.2.5   2018-10-11 [1] CRAN (R 3.5.1)
##  tidyverse   * 1.3.0   2019-11-21 [1] CRAN (R 3.6.1)
##  usethis       1.5.1   2019-07-04 [1] CRAN (R 3.6.1)
##  utf8          1.1.4   2018-05-24 [1] CRAN (R 3.5.1)
##  vctrs         0.2.0   2019-07-05 [1] CRAN (R 3.6.1)
##  viridisLite   0.3.0   2018-02-01 [1] CRAN (R 3.5.1)
##  webshot       0.5.2   2019-11-22 [1] CRAN (R 3.6.1)
##  withr         2.1.2   2018-03-15 [1] CRAN (R 3.5.1)
##  xfun          0.11    2019-11-12 [1] CRAN (R 3.6.1)
##  xml2          1.2.2   2019-08-09 [1] CRAN (R 3.6.1)
##  yaml          2.2.0   2018-07-25 [1] CRAN (R 3.5.1)
##  zeallot       0.1.0   2018-01-28 [1] CRAN (R 3.5.3)
## 
## [1] C:/R/R-3.6.1/library