knitr::opts_chunk$set(
    message = FALSE,
    warning = FALSE,
    comment = NA
)

First we load the .csv file containing the list of GPs across UK obtained from the NHS Digital Services

library(readr)
library(kableExtra)
epraccur <- read_csv("~/Git/Notts_GP_map/epraccur.csv", col_names = FALSE)

knitr::kable(head(epraccur), "html") %>%
    kable_styling() %>%
    scroll_box(width = "900px", height = "500px")
X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26 X27
A81001 THE DENSHAM SURGERY Y63 QHM THE HEALTH CENTRE LAWSON STREET STOCKTON-ON-TEES CLEVELAND NA TS18 1HU 19740401 NA A B 16C 20200401 NA 01642 672351 NA NA NA 0 NA 16C NA 4 NA
A81002 QUEENS PARK MEDICAL CENTRE Y63 QHM QUEENS PARK MEDICAL CTR FARRER STREET STOCKTON ON TEES CLEVELAND NA TS18 2AW 19740401 NA A B 16C 20200401 NA 01642 679681 NA NA NA 0 NA 16C NA 4 NA
A81003 VICTORIA MEDICAL PRACTICE Y54 Q74 THE HEALTH CENTRE VICTORIA ROAD HARTLEPOOL CLEVELAND NA TS26 8DB 19740401 20171031 C B 00K 20130401 20171031 01429 272945 NA NA NA 0 NA 00K NA 4 NA
A81004 ACKLAM MEDICAL CENTRE Y63 QHM TRIMDON AVENUE ACKLAM MIDDLESBROUGH CLEVELAND NA TS5 8SB 19740401 NA A B 16C 20200401 NA 01642 827697 NA NA NA 0 NA 16C NA 4 NA
A81005 SPRINGWOOD SURGERY Y63 QHM SPRINGWOOD SURGERY RECTORY LANE GUISBOROUGH NA NA TS14 7DJ 19740401 NA A B 16C 20200401 NA 01287 619611 NA NA NA 0 NA 16C NA 4 NA
A81006 TENNANT STREET MEDICAL PRACTICE Y63 QHM TENNANT ST MEDICAL PRACT TENNANT STREET STOCKTON-ON-TEES CLEVELAND NA TS18 2AT 19740401 NA A B 16C 20200401 NA 01642 613331 NA NA NA 0 NA 16C NA 4 NA

It does not include a header, has 15536 rows and 27 columns. The columns are the following:

  1. Organisation Code
  2. Name
  3. National Grouping
  4. High Level Health Geography
  5. Address Line 1
  6. Address Line 2
  7. Address Line 3
  8. Address Line 4
  9. Address Line 5
  10. Postcode
  11. Open Date
  12. Close Date
  13. Status Code
  14. Organisation Sub-Type Code
  15. Commissioner
  16. Join Provider/Purchaser Date
  17. Provider/Purchaser Date
  18. Contact Telephone Number
  19. Null
  20. Null
  21. Null
  22. Amended Record Indicator
  23. Null
  24. Provider/Purchaser
  25. Null
  26. Prescribing Setting
  27. Null

We proceed to filter the ones in Nottinghamshire, get the column with the name of the GP and the 4 address columns, and combine the last 4 columns in order to create an address to send to the API.

library(dplyr)
library(tidyr)

GP_NOTTS<- filter(epraccur, 'NOTTINGHAMSHIRE'==X8)
GP_NOTTS<- select (GP_NOTTS, c(2,5,6,7,8))
GP_NOTTS<- unite(GP_NOTTS, 'address', c(2,3,4,5), sep = ",", remove = TRUE, na.rm = FALSE)
GP_NOTTS<- rename(GP_NOTTS,"name" = "X2")
knitr::kable(head(GP_NOTTS),format="markdown")
name address
CRESWELL MEDICAL CENTRE CRESWELL MEDICAL CENTRE,WELBECK STREET,CRESWELL,WORKSOP,NOTTINGHAMSHIRE
ADAM HOUSE MEDICAL CENTRE ADAM HOUSE MEDICAL CENTRE,85-91 DERBY RD,SANDIACRE,NOTTINGHAM,NOTTINGHAMSHIRE
SHIRES HEALTHCARE SHIRES HEALTHCARE,18 MAIN STREET,SHIREBROOK,MANSFIELD,NOTTINGHAMSHIRE
CRAG’S HEALTH CARE CRAGS HEALTH CARE,174 ELMTON RD, CRESWELL,WORKSOP,NOTTINGHAMSHIRE
COLLEGE STREET MEDICAL PRACTICE COLLEGE ST. MED PRACTICE,86 COLLEGE ST,LONG EATON,NOTTINGHAM,NOTTINGHAMSHIRE
ORCHARD SURGERY ORCHARD SURGERY,THE DRAGWELL, KEGWORTH,DERBY,NOTTINGHAMSHIRE

There are 141 GP practices in nottinghamshire. We proceed to search the latitude and longitude via the tidygeocoder library via the “arcgis” API, because its free and finds all the addresses (other services such as google were paid or failed to identify them all).

library(tidygeocoder)

lat_longs_name <- GP_NOTTS %>%
  geocode(address, method = 'arcgis', lat = latitude , long = longitude)

we proceed to remove the ones the API could not find.

lat_longs_name<-as_tibble(lat_longs_name) 
lat_longs_name<-lat_longs_name %>% drop_na(longitude)
knitr::kable(head(lat_longs_name),format="markdown")
name address latitude longitude
CRESWELL MEDICAL CENTRE CRESWELL MEDICAL CENTRE,WELBECK STREET,CRESWELL,WORKSOP,NOTTINGHAMSHIRE 53.26119 -1.215057
ADAM HOUSE MEDICAL CENTRE ADAM HOUSE MEDICAL CENTRE,85-91 DERBY RD,SANDIACRE,NOTTINGHAM,NOTTINGHAMSHIRE 52.92233 -1.294010
SHIRES HEALTHCARE SHIRES HEALTHCARE,18 MAIN STREET,SHIREBROOK,MANSFIELD,NOTTINGHAMSHIRE 53.20245 -1.215490
CRAG’S HEALTH CARE CRAGS HEALTH CARE,174 ELMTON RD, CRESWELL,WORKSOP,NOTTINGHAMSHIRE 53.26042 -1.222705
COLLEGE STREET MEDICAL PRACTICE COLLEGE ST. MED PRACTICE,86 COLLEGE ST,LONG EATON,NOTTINGHAM,NOTTINGHAMSHIRE 52.90456 -1.282956
ORCHARD SURGERY ORCHARD SURGERY,THE DRAGWELL, KEGWORTH,DERBY,NOTTINGHAMSHIRE 52.83643 -1.278070

The API found all the longitudes and latitudes. We use this information to plot the Map via the leaflet library and add the names of the places on the markers.

library(leaflet)
lat_longs_name %>% 
  leaflet() %>%
  addTiles() %>%
  addMarkers() %>%
  addLabelOnlyMarkers(lng = ~longitude, lat = ~latitude, label =~as.character(name),
                      labelOptions = labelOptions(noHide = TRUE, textOnly = FALSE, 
                                                direction = "bottom", offset = c(0,5)))