library(fingertipsR) ## for interacting with the Fingertips API
library(tidyverse, warn.conflicts = FALSE) ## packages for data manipulation and plotting
library(stringr) ## text manipulation
library(Hmisc) ## data description
library(corrr) ## calcuate correlation matrices
library(ggraph) ## plot as network charts
library(igraph, warn.conflicts = FALSE) ## network tools
profiles <- profiles()
profiles %>% select(ProfileID, ProfileName) %>% distinct() %>%
knitr::kable(align = "l")
ProfileID | ProfileName |
---|---|
8 | Adult Social Care |
18 | Local Tobacco Control Profiles |
19 | Public Health Outcomes Framework |
20 | National General Practice Profiles |
21 | National General Practice Profiles (supporting indicators) |
22 | Longer Lives |
26 | Health Profiles |
29 | Inhale - INteractive Health Atlas of Lung conditions in England |
30 | Health Protection |
32 | NCMP Local Authority Profile |
36 | Mental Health Dementia and Neurology |
37 | Disease and risk factor prevalence |
39 | Public Health and NHS Outcomes Frameworks for Children |
40 | Common Mental Health Disorders |
41 | Severe Mental Illness |
45 | Sexual and Reproductive Health Profiles |
46 | Atlas of Variation |
51 | Diabetes |
53 | Cardiovascular Disease Profiles |
55 | Liver Disease Profiles |
58 | Learning Disability Profiles |
59 | Diabetes - Longer Lives - Supporting Indicators |
61 | Neurology Profiles |
65 | NHS Health Check |
67 | Hypertension |
72 | Children’s and Young People’s Mental Health and Wellbeing |
73 | Suicide Prevention - Longer Lives |
75 | Drugs and Alcohol - Longer Lives |
77 | NHS Health Check - Longer Lives |
79 | Co-occurring substance misuse and mental health issues |
82 | Hypertension - Supporting Indicators |
84 | Dementia Profile |
86 | TB Strategy Monitoring Indicators |
87 | Local Alcohol Profiles for England |
91 | Suicide Prevention Profile |
92 | Cancer Services |
93 | Peer benchmarking tool |
94 | Health behaviours in young people – What About YOUth? survey |
95 | End of Life Care Profiles |
98 | Mental Health JSNA |
99 | Physical Activity |
101 | AMR local indicators |
103 | Older People’s Health and Wellbeing |
106 | Crisis Care Profile |
108 | Segment Tool |
109 | Marmot Indicators for Local Authorities |
110 | Healthy life expectancy and life expectancy around the 2011 Census: Marmot Indicators |
111 | Marmot Indicators |
112 | Mortality |
113 | Early years |
114 | School-age children |
115 | Young people |
116 | Child and Maternal Health |
119 | Overview of child health |
120 | Pregnancy and birth |
121 | Obesity |
122 | Breastfeeding |
123 | Unintentional injuries |
124 | Vaccinations and immunisations |
126 | Healthcare use |
127 | Vulnerable children and young people |
128 | Long term conditions and complex health needs |
129 | Health behaviours in young people |
130 | Wider Determinants of Health |
131 | Oral Health Profile |
132 | Populations |
134 | Suicide Prevention - Longer Lives (supporting indicators) |
options(digits = 2)
profile_name <- filter(profiles, ProfileID == 26) %>% select(ProfileName) %>% distinct()
hp_data <- fingertips_data(ProfileID = 26)
unique(hp_data$IndicatorName)
## [1] Deprivation score (IMD 2015)
## [2] Children in low income families (under 16s)
## [3] Statutory homelessness
## [4] GCSEs achieved
## [5] Violent crime (violence offences)
## [6] Long term unemployment
## [7] Smoking status at time of delivery
## [8] Breastfeeding initiation
## [9] Obese children (Year 6)
## [10] Under 18 conceptions
## [11] Admission episodes for alcohol-specific conditions - Under 18s
## [12] Smoking Prevalence in adults
## [13] Percentage of physically active adults
## [14] Excess weight in adults
## [15] Cancer diagnosed at early stage
## [16] Hospital stays for self-harm
## [17] Admission episodes for alcohol-related conditions - narrow definition
## [18] Recorded diabetes
## [19] Incidence of TB
## [20] New sexually transmitted infections (STI)
## [21] Hip fractures in people aged 65 and over
## [22] Life expectancy at birth
## [23] Infant mortality
## [24] Killed and seriously injured on roads
## [25] Suicide rate
## [26] Smoking related deaths
## [27] Under 75 mortality rate: cardiovascular
## [28] Under 75 mortality rate: cancer
## [29] Excess winter deaths
## [30] Slope index of inequality in life expectancy at birth within English local authorities, based on local deprivation deciles within each area
## [31] The percentage of people resident in the area living in each national deprivation quintile
## [32] Premature mortality from all causes
## [33] Per cent of ethnic minorities
## [34] Dependency ratio
## 34 Levels: Admission episodes for alcohol-related conditions - narrow definition ...
This part of the script:
## scale the data
hp_data1 <- hp_data %>%
mutate_if(is.factor, as.character) %>%
filter(CategoryType == "", AreaType == "County & UA" ) %>%
janitor::clean_names() %>%
select(indicatorname, areaname, age, sex, timeperiod, value) %>%
group_by(indicatorname, sex) %>%
filter(timeperiod == max(timeperiod)) %>%
mutate(index = paste(sex, "-",age , "-",timeperiod, "-", indicatorname) ) %>%
ungroup() %>%
select(-c(indicatorname, sex, age, timeperiod)) %>%
distinct() %>%
spread(index, value) %>%
janitor::clean_names() %>%
mutate_if(is.numeric, funs(impute(., mean))) %>%
mutate_if(is.numeric, funs(scale(.)))
This code:
## see https://drsimonj.svbtle.com/how-to-create-correlation-network-plots-with-corrr-and-ggraph
hp_cor <- hp_data1 %>%
select(3:ncol(.)) %>%
correlate() %>%
stretch()
graph_cors <- hp_cor %>%
filter(abs(r) > 0.7) %>%
graph_from_data_frame(directed = FALSE)
ggraph(graph_cors, layout = "igraph", algorithm = "nicely") +
geom_edge_link(aes(edge_alpha = abs(r), color = r, label = round(r,2)), label_size = 2) +
guides(edge_alpha = "none", edge_width = "none") +
scale_edge_colour_gradientn(limits = c(-1, 1), colors = c("firebrick2", "dodgerblue2")) +
geom_node_point(color = "black", size = 3) +
geom_node_point() +
geom_node_text(aes(label = str_wrap(substring(name, 1,70), 30)), size = 2, repel = TRUE) +
theme_graph() +
labs(title = paste("Correlation map of ", profile_name$ProfileName, "profile"))