# Plotting healthy life expectancy and life expectancy by deprivation for English local authorities

This worked example attempts to document a common workflow a user might follow when using the fingertipsR package.

fingertipsR provides users the ability to import data from the Fingertips website. Fingertips is a major repository of public health indicators in England. The site is structured in the following way:

• Profiles - these contain indicators related to a broad theme (such as a risk factor or a disease topic etc)
• Domains - these are subcategories of profiles, and break the profiles down to themes within the broader theme
• Indicators - this is the lowest level of the structure and sit within the domains. Indicators are presented at different time periods, geographies, sexes, ageband and categories.

This example demonstrates how you can plot healthy life expectancy and life expectancy by deprivation for a given year of data that fingertips contains. So, where to start?

## Where to start

There is one function in the fingertipsR package that extracts data from the Fingertips API: fingertips_data(). This function has the following inputs:

• IndicatorID
• AreaCode
• DomainID
• ProfileID
• AreaTypeID (this defaults to 102; County and Unitary Authority)
• ParentAreaTypeID (this defaults to 6 for an AreaTypeID of 102; Government Office Region)

At least one of IndicatorID, DomainID or ProfileID must be complete. These fields relate to each other as described in the introduction. AreaCode needs completing if you are extracting data for a particular area or group of areas only. AreaTypeID determines the geography to extract the data for. In this case we want County and Unitary Authority level. ParentAreaTypeID requires an area type code that the AreaTypeID maps to at a higher level of geography. For example, when combining groups of County and Unitary Authorities it is possible to create Goverenment Office Regions. These mappings can be identified using the area_types() funciton. If ignored, a ParentAreaTypeID will be chosen automatically.

Therefore, the inputs to the fingertips_data function that we need to find out are the ID codes for:

• IndicatorID
• AreaTypeID
• ParentAreaTypeID

We need to begin by calling the fingertipsR package:

library(fingertipsR)

## IndicatorID

There are two indicators we are interested in for this exercise. Without consulting the Fingertips website, we know approximately what they are called:

• Healthy life expectancy
• Life expectancy

We can use the indicators() function to return a list of all the indicators within Fingertips. We can then filter the name field for the term life expectancy (note, the IndicatorName field has been converted to lower case in the following code chunk to ensure matches will not be overlooked as a result of upper case letters).

inds <- indicators_unique()

## Deprivation

We want to plot life expectancy against deprivation information. As deprivation is a notable cause of health inequalities, the deprivation_deciles() function has been provided to allow easy access to this information. This is populated from the Department for Communities and Local Government Indices of Multiple Deprivation (IMD). Note, there is only information for General Practices, upper and lower tier local authorities (AreaTypeID = 7, 102 and 101 respectively). IMD has only been produced for the years 2010 and 2015 (for the latter areas) as well as 2011 and 2012 for General Practices.

dep <- deprivation_decile(AreaTypeID = 102, Year = 2015)
DT::datatable(dep, filter = "top", rownames = FALSE) #note, this line will only work in a markdown file (*.Rmd). It presents the table for a report

Now we need to merge this with the main dataset:

# merge deprivation onto data
data <- merge(data, dep, by.x = "AreaCode", by.y = "AreaCode", all.x = TRUE)

# remove NA values
data <- data[complete.cases(data),]
DT::datatable(data, filter = "top", rownames = FALSE) #note, this line will only work in a markdown file (*.Rmd). It presents the table for a report

## Plotting outputs

Using ggplot2 it is possible to plot the outputs.

library(ggplot2)
p <- ggplot(data, aes(x = IMDscore, y = Value, col = factor(IndicatorID)))
p <- p +
geom_point() +
geom_smooth(se = FALSE, method = "loess") +
facet_wrap(~ Sex) +
scale_colour_manual(name = "Indicator",
breaks = c("90366", "90362"),
labels = c("Life expectancy", "Healthy life expectancy"),
values = c("#128c4a", "#88c857")) +
scale_x_reverse() +
labs(x = "IMD deprivation",
y = "Age",
title = "Life expectancy and healthy life expectancy at birth \nfor Upper Tier Local Authorities (2012 - 2014)") +
theme_bw()
print(p)